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("&","&amp;",$xmlstr);   $xml = simplexml_load_string($xmlstr);   $abc = $xml->book[0]->title[0];   echo $abc; 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -