【发布时间】:2020-04-27 06:08:22
【问题描述】:
我想将文本字符串“hello there”分成两行。
为此,我需要 simpleXML 在输出文件 result.xml 中创建“br-tag”,但我只生成了代码 <br>。
<?php
// DOMDocument
$dom = new DomDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$html = $dom->appendChild($dom->createElement("html"));
$xmlns = $dom->createAttribute('xmlns');
$xmlns->value = 'http://www.w3.org/1999/xhtml';
$html->appendChild($xmlns);
// SimpleXML
$sxe = simplexml_import_dom($dom);
$head = $sxe->addChild('head', ' ');
$body = $sxe->addChild('body', 'hello <br> there');
echo $sxe->asXML('result.xml');
结果:
hello <br> there
想要的结果:
你好
那里
【问题讨论】:
标签: php newline simplexml domdocument