1

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->getElementsByTagName("name");

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

}

$xml_Document->save('test.xml');
Cœur
  • 37,241
  • 25
  • 195
  • 267
user586445
  • 19
  • 1
  • 3
  • see if this one solves it: [php: using DomDocument whenever I try to write UTF-8 it writes the hexadecimal notation of it.](http://stackoverflow.com/questions/3575109/php-using-domdocument-whenever-i-try-to-write-utf-8-it-writes-the-hexadecimal-no) – Gordon Jan 23 '11 at 16:02
  • 1
    libxml2 seems to explicitly escapes `\r` to ` ` – Arnaud Le Blanc Jan 23 '11 at 17:19

1 Answers1

2

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

kalkin
  • 870
  • 1
  • 8
  • 15