Saturday, March 24, 2007

Needing PHP5's simplexml_load_file function but have PHP4?

If you are using PHP Proxy to deal with Cross Domain Security issues with Adobe Flex for things such as RSS feeds but have PHP4 instead of PHP5 you can do the following.

PHP5 makes it looks so nice

<?php
$url = $_POST['url'];
$xml = simplexml_load_file($url, "r");
echo $xml->asXML();
?>


PHP4's equivalent

<?php
$url = $_POST['url'];
$handle = @fopen($url, "r");
if($handle)
{
while(!feof($handle))
{
$buffer = fgets($handle, 4096);
echo $buffer;
}
fclose($handle);
}
?>


Cheers

Matt

Additional Reading
TechNote : Loading data across domains

0 comments: