新聞中心
/**
你所需要的網(wǎng)站建設(shè)服務(wù),我們均能行業(yè)靠前的水平為你提供.標(biāo)準(zhǔn)是產(chǎn)品質(zhì)量的保證,主要從事成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、企業(yè)網(wǎng)站建設(shè)、手機(jī)網(wǎng)站制作、網(wǎng)頁設(shè)計(jì)、成都品牌網(wǎng)站建設(shè)、網(wǎng)頁制作、做網(wǎng)站、建網(wǎng)站。創(chuàng)新互聯(lián)擁有實(shí)力堅(jiān)強(qiáng)的技術(shù)研發(fā)團(tuán)隊(duì)及素養(yǎng)的視覺設(shè)計(jì)專才。
- 根據(jù)HTML代碼獲取word文檔內(nèi)容
- 創(chuàng)建一個本質(zhì)為mht的文檔,該函數(shù)會分析文件內(nèi)容并從遠(yuǎn)程下載頁面中的圖片資源
- 該函數(shù)依賴于類WordMake
- 該函數(shù)會分析img標(biāo)簽,提取src的屬性值。但是,src的屬性值必須被引號包圍,否則不能提取
- @param string $content HTML內(nèi)容
- @param string $absolutePath 網(wǎng)頁的絕對路徑。如果HTML內(nèi)容里的圖片路徑為相對路徑,那么就需要填寫這個參數(shù),來讓該函數(shù)自動填補(bǔ)成絕對路徑。這個參數(shù)最后需要以/結(jié)束
- @param bool $isEraseLink 是否去掉HTML內(nèi)容中的鏈接
*/
// 手動下載下Wordmaker
function WordMake( $content , $absolutePath = "" , $isEraseLink = true )
{
import("ORG.Util.Wordmaker");
$mht = new \MhtFileMaker();
if ($isEraseLink){
$content = preg_replace('/.?\s>(\s.?\s)<\/a>/i' , '$1' , $content); //去掉鏈接
}
$images = array();
$files = array();
$matches = array();
//這個算法要求src后的屬性值必須使用引號括起來
if ( preg_match_all('/?src\s?=\s?[\"\'](.?)\"\'\/>/i',$content ,$matches ) ){
$arrPath = $matches[1];
for ( $i=0;$i
$path = $arrPath[$i];
$imgPath = trim( $path );
if ( $imgPath != "" )
{
$files[] = $imgPath;
if( substr($imgPath,0,7) == 'http://')
{
//絕對鏈接,不加前綴
}
else
{
$imgPath = $absolutePath.$imgPath;
}
$images[] = $imgPath;
}
}
}
$mht->AddContents("tmp.html",$mht->GetMimeType("tmp.html"),$content);
for ( $i=0;$i
$image = $images[$i];
if ( @fopen($image , 'r') )
{
$imgcontent = @file_get_contents( $image );
if ( $content )
$mht->AddContents($files[$i],$mht->GetMimeType($image),$imgcontent);
}
else
{
echo "file:".$image." not exist!
";
}
}
return $mht->GetFile();
}
function GenerateWord($content){
$_path='Uploads/word/'.date('Y-m-d',time()).'/';
if (!file_exists($_path)){ mkdir ($_path); }
$content = iconv("utf-8", "GBK",$content);
$rand=rand(1000,9999);
$fileContent = WordMake($content,$url);//生成word內(nèi)容
$fp = fopen($_path.$name.time().$rand.".doc", 'w');//打開生成的文檔
fwrite($fp, $fileContent);//寫入包保存文件
fclose($fp);
return $_path.$name.time().$rand.".doc";
}
本文名稱:PHPHTML生成word
本文來源:http://ef60e0e.cn/article/pgodpg.html