Monday, July 8, 2013

Get value of inside of "![CDATA" In PHP

If you have XML File and in this file data was stored like this.
"
<tourlist>
<item>
<tourName>
<![CDATA[Milano Card]]>
</tourName>
<tourCity>
<![CDATA[Milan]]>
</tourCity>
<tourCountry>
<![CDATA[Italy]]>
</tourCountry>
<highlights>
<![CDATA[Get all that you need at Milan and discover the heart of Europe from culture art entertainment and cuisine. Choose the service that you want and use your Milano Card for perks and discounts. Get to use public transportation for free for 3 days and gain free access to selected museums!]]>
</highlights>
</item>
</tourlist>
"
And if you want to get this data using PHP script  then execute this code. 

<?php 

  $doc = new DOMDocument();
  $doc->load('http://' . $_SERVER['HTTP_HOST'] . '/citytoursxmlfiles/city.xml' );
   $destinations = $doc->getElementsByTagName("item");
   $simpleXml = array();
   foreach ($destinations as $destination) {
            $simpleXml[] = $destination->nodeValue;
     }
      echo json_encode($simpleXml); 

?>

No comments:

Post a Comment