0

我正在使用 PHPWord 创建一个 word 文档。文档的内容是动态的,内容可能包含 HTML 标签,如下所示:

<strong>Problem statement</strong>

<p>The text may be<em>bold</em> subject to very peculiar conditions</p>

<ul>
    <li>Test 1</li>
    <li>Test 2</li>
</ul>

文档正在创建,但文档中的内容显示了 html 标签。

如何用正确的 word 文档标签替换这些标签,以便 word doc 显示与具有正确格式的 HTML 视图完全相同。

4

2 回答 2

0

我建议做一个这样的功能:

function convertTags($text){
        $text= str_replace("<strong>", "<w:b val="true"/>", $text);
        $text= str_replace("</string>", "<w:b val="false"/>", $text);
        // and all the tags like that. You may use an array and loop through it.
       return $text;
    }
于 2015-05-12T08:10:27.593 回答
0

用于str_replace将 html-tags 替换为 word-tags。例子:

$str = "<b>Hello World</b>";
$str = str_replace("<b>", "<strong>", $str);
$str = str_replace("</b>", "</strong>", $str);
//Gives "<strong>Hello World</strong>"

在这里阅读更多

于 2015-05-12T08:12:21.987 回答