<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Quick PHP Tip: How to parse CDATA sections using SimpleXML</title>
	<atom:link href="http://www.vijayjoshi.org/2009/09/22/quick-php-tip-how-to-parse-cdata-sections-using-simplexml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vijayjoshi.org/2009/09/22/quick-php-tip-how-to-parse-cdata-sections-using-simplexml/</link>
	<description>php &#124; javascript &#124; ajax &#124; and all things web</description>
	<lastBuildDate>Sat, 04 Feb 2012 08:50:42 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: andrew</title>
		<link>http://www.vijayjoshi.org/2009/09/22/quick-php-tip-how-to-parse-cdata-sections-using-simplexml/comment-page-1/#comment-38615</link>
		<dc:creator>andrew</dc:creator>
		<pubDate>Sun, 18 Sep 2011 07:43:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.vijayjoshi.org/?p=393#comment-38615</guid>
		<description>Have following PHP which gives me car hire location, time and date but i cannot seem to extract the CDATA? All data comes from the following and included in this is CDATA

$string=&quot;http://www.thrifty.co.uk/cgi-bin/gen5?runprog=thxml&amp;xsrc=7qhfqou3&amp;mode=quote&quot;;

Any ideas????


 $value )
    {
        $value = ( array ) $value ;
        if ( isset ( $value [ 0 ] ) )
        {
            $newArray [ $key ] = trim ( $value [ 0 ] ) ;
        }
        else
        {
            $newArray [ $key ] = XML2Array ( $value , true ) ;
        }
    }
    return $newArray ;
}

function disp_date($str)
{
$y=substr($str,0,4);
$m=substr($str,4,2);
$d=substr($str,6,2);
//echo $y.&quot;-&quot;.$m.&quot;-&quot;.$d;
return date(&quot;M d, Y&quot;,strtotime($y.&quot;-&quot;.$m.&quot;-&quot;.$d));
}

$handle = fopen($string, &quot;r&quot;);
$xml_string=&quot;&quot;;
// If there is something, read and return
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        $xml_string.=$buffer;
    }
    fclose($handle);
}

//$xmlDoc = new DOMDocument();
$xmlDoc=simplexml_load_string ( $xml_string ) ;

//print_r($xmlDoc);

echo &quot;Zipcode: &quot;.$xmlDoc-&gt;hire-&gt;loccode.&quot;Location Name: &quot;.$xmlDoc-&gt;hire-&gt;locname.&quot;Pickup Time: &quot;.disp_date($xmlDoc-&gt;hire-&gt;pickupdate).&quot; &quot;.$xmlDoc-&gt;hire-&gt;pickuptime.&quot;Dropback Time: &quot;.disp_date($xmlDoc-&gt;hire-&gt;dropbackdate).&quot; &quot;.$xmlDoc-&gt;hire-&gt;dropbacktime.&quot;&quot;;

echo &quot;Car TypeDescriptionRate&quot;;
foreach($xmlDoc-&gt;car as $car)
{
echo &quot;carimage.&quot;&#039; align=&#039;right&#039; style=&#039;padding:5px; width:64px&#039;&gt;&lt;b&gt;&quot;.$car-&gt;cartype.&quot;&lt;/b&gt;&quot;.$car-&gt;carsipp.&quot;&quot;.$car-&gt;transmission.&quot;&lt;b&gt;&quot;.$car-&gt;carexample.&quot;&lt;/b&gt;&lt;b&gt;&#163;&quot;.$car-&gt;price.&quot;/day&lt;/b&gt;Unlimited Miles&quot;;
}
echo &quot;&quot;;
?&gt;</description>
		<content:encoded><![CDATA[<p>Have following PHP which gives me car hire location, time and date but i cannot seem to extract the CDATA? All data comes from the following and included in this is CDATA</p>
<p>$string=&#8221;http://www.thrifty.co.uk/cgi-bin/gen5?runprog=thxml&amp;xsrc=7qhfqou3&amp;mode=quote&#8221;;</p>
<p>Any ideas????</p>
<p> $value )<br />
    {<br />
        $value = ( array ) $value ;<br />
        if ( isset ( $value [ 0 ] ) )<br />
        {<br />
            $newArray [ $key ] = trim ( $value [ 0 ] ) ;<br />
        }<br />
        else<br />
        {<br />
            $newArray [ $key ] = XML2Array ( $value , true ) ;<br />
        }<br />
    }<br />
    return $newArray ;<br />
}</p>
<p>function disp_date($str)<br />
{<br />
$y=substr($str,0,4);<br />
$m=substr($str,4,2);<br />
$d=substr($str,6,2);<br />
//echo $y.&#8221;-&#8221;.$m.&#8221;-&#8221;.$d;<br />
return date(&#8220;M d, Y&#8221;,strtotime($y.&#8221;-&#8221;.$m.&#8221;-&#8221;.$d));<br />
}</p>
<p>$handle = fopen($string, &#8220;r&#8221;);<br />
$xml_string=&#8221;";<br />
// If there is something, read and return<br />
if ($handle) {<br />
    while (!feof($handle)) {<br />
        $buffer = fgets($handle, 4096);<br />
        $xml_string.=$buffer;<br />
    }<br />
    fclose($handle);<br />
}</p>
<p>//$xmlDoc = new DOMDocument();<br />
$xmlDoc=simplexml_load_string ( $xml_string ) ;</p>
<p>//print_r($xmlDoc);</p>
<p>echo &#8220;Zipcode: &#8220;.$xmlDoc-&gt;hire-&gt;loccode.&#8221;Location Name: &#8220;.$xmlDoc-&gt;hire-&gt;locname.&#8221;Pickup Time: &#8220;.disp_date($xmlDoc-&gt;hire-&gt;pickupdate).&#8221; &#8220;.$xmlDoc-&gt;hire-&gt;pickuptime.&#8221;Dropback Time: &#8220;.disp_date($xmlDoc-&gt;hire-&gt;dropbackdate).&#8221; &#8220;.$xmlDoc-&gt;hire-&gt;dropbacktime.&#8221;";</p>
<p>echo &#8220;Car TypeDescriptionRate&#8221;;<br />
foreach($xmlDoc-&gt;car as $car)<br />
{<br />
echo &#8220;carimage.&#8221;&#8216; align=&#8217;right&#8217; style=&#8217;padding:5px; width:64px&#8217;&gt;<b>&#8220;.$car-&gt;cartype.&#8221;</b>&#8220;.$car-&gt;carsipp.&#8221;".$car-&gt;transmission.&#8221;<b>&#8220;.$car-&gt;carexample.&#8221;</b><b>&pound;&#8221;.$car-&gt;price.&#8221;/day</b>Unlimited Miles&#8221;;<br />
}<br />
echo &#8220;&#8221;;<br />
?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dVyper</title>
		<link>http://www.vijayjoshi.org/2009/09/22/quick-php-tip-how-to-parse-cdata-sections-using-simplexml/comment-page-1/#comment-13291</link>
		<dc:creator>dVyper</dc:creator>
		<pubDate>Thu, 13 Jan 2011 15:11:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.vijayjoshi.org/?p=393#comment-13291</guid>
		<description>This has proved very helpful thanks!</description>
		<content:encoded><![CDATA[<p>This has proved very helpful thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rajaraman</title>
		<link>http://www.vijayjoshi.org/2009/09/22/quick-php-tip-how-to-parse-cdata-sections-using-simplexml/comment-page-1/#comment-10846</link>
		<dc:creator>Rajaraman</dc:creator>
		<pubDate>Thu, 29 Jul 2010 06:23:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.vijayjoshi.org/?p=393#comment-10846</guid>
		<description>thanks</description>
		<content:encoded><![CDATA[<p>thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>

