开发者

Escape newline encryption (&#13) in XML while update using DOM PHP

I tried to update xml node value by posted PHP value. My problem, after save the XML, can look like

<name>test&#13;
test123</name>

My expect result is

<name>test
test123</name>

My source

$xml_Document = new DOMDocument();
$xml_Document->load('test.xml');

$employees = $xml_Document->getElementsByTagName("employees");

foreach( $employees as $employee )
{
$names = $employee->getElementsByTagNa开发者_如何学运维me("name");

$names->item(0)->nodeValue = $_POST["text1"];

}

$xml_Document->save('test.xml');


I think this will fix your problem $names->item(0)->nodeValue = str_replace(chr(13), '', $_POST["text1"]);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜