background image

                {
                    //绝对链接,不加前缀
                }
                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();

}

使用方法:

代码如下

:

$fileContent = getWordDocument($content,"http://www.jb51.net/Music/etc/");

$fp = fopen("test.doc", 'w');
fwrite($fp, $fileContent);
fclose($fp);

其中,

$content 变量应该是 HTML 源代码,后面的链接应该是能填补 HTML 代码中图

片相对路径的

URL 地址

注意,在使用这个函数之前,您需要先包含类

MhtFileMaker,这个类可以帮助我们生成