PHPHTML生成word

/**

你所需要的網(wǎng)站建設(shè)服務(wù),我們均能行業(yè)靠前的水平為你提供.標(biāo)準(zhǔn)是產(chǎn)品質(zhì)量的保證,主要從事成都網(wǎng)站設(shè)計、成都做網(wǎng)站、企業(yè)網(wǎng)站建設(shè)、手機網(wǎng)站制作、網(wǎng)頁設(shè)計、成都品牌網(wǎng)站建設(shè)、網(wǎng)頁制作、做網(wǎng)站、建網(wǎng)站。創(chuàng)新互聯(lián)擁有實力堅強的技術(shù)研發(fā)團隊及素養(yǎng)的視覺設(shè)計專才。

  • 根據(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ù)自動填補成絕對路徑。這個參數(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('/<a\s.?\s>(\s.?\s)<\/a>/i' , '$1' , $content); //去掉鏈接
}
$images = array();
$files = array();
$matches = array();
//這個算法要求src后的屬性值必須使用引號括起來
if ( preg_match_all('/<img[.\n]?src\s?=\s?[\"\'](.?)\"\'\/>/i',$content ,$matches ) ){
$arrPath = $matches[1];
for ( $i=0;$i<count($arrPath);$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<count($images);$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!<br />";
}
}
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";

}

當(dāng)前標(biāo)題:PHPHTML生成word
路徑分享:http://muchs.cn/article36/pgodpg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、自適應(yīng)網(wǎng)站、定制開發(fā)建站公司、網(wǎng)站制作、云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化