xml - PHP SimpleXMLElement: How to add dynamic child with ampersand escaping -
i'm using following code add dynamic child xml node
<?php $recordxml = new simplexmlelement("<record></record>"); $rowxml = $recordxml->addchild('row'); foreach ($array $column => $column_value) { $rowxml->addchild($column,$column_value ); }
this code gives "unterminated entity reference" warning!
when there ampresand &
in of $column_value
, know &
can escaped if assign child content below
$rowxml->column_name = "text & content"; // gives <row><column_name>text & content </column_name></row> // without warning
now how use method add dynamic child node ampresand escaping ?
basically make work would have this:
$rowxml->{$column} = $column_value;
Comments
Post a Comment