php - Get a special charactor in a XML file using simplexml and CDATA -
i trying retreive string in xml file using simplexml. string contains character "&". think have use cdata value. new , don't no how it. example of want.
example.php
<?php $xmlstr = <<<xml <?xml version='1.0' standalone='yes'?> <books> <book> <title> php & xml </title> <author> text </author> <price> text </price> </book> <book> <title> java & coding </title> <author> text </author> <price> text </price> </book> </books> xml; ?> and calling php file
call.php
<?php include 'example.php'; $xml = simplexml_load_string($xmlstr); $abc = $xml->book[0]->title[0]; echo $abc; ?> and giving error because of character "&". cannot change xml. modification can done call.php regarding matter highly appreciate. thanx.
you have exact question php, simplexml, decoding entities in cdata
it has explain cdata can used in case of
special characters (in particular, >, < , &) escaped. cdata section containing character & same normal text node containing &.
have on this.
edit
here 1 solution if load every time example.php code string below 1 solution.
$xmlstr = str_replace("&","&",$xmlstr); $xml = simplexml_load_string($xmlstr); $abc = $xml->book[0]->title[0]; echo $abc;
Comments
Post a Comment