Jump to content

Reading XML with PHP


CoreyR

Recommended Posts

I am reading in a file. Here is one of the tags from the XML.

<PropertyURL>http://developer.newcondosonline.com/direct1.php?property=1568&amp;pname=The Potrero&amp;compid=626</PropertyURL>

 

When I grab the URL all I get is "compid=626" because the & breaks the data. Anyone know how to bring this in without breaking this?

 

Or, possibly replace the characters when I down load the file?

 

$sf = "http://developer.newcondosonline.com/rss-properties-san-francisco.xml";
$sfxml = "sf.xml";
$source = $sf;
$dest = $sfxml;
if (!copy($source, $dest)) 	{print ("failed to copy $dest. It is possible the XML feed has been changed, please check with provider.<br>\n");}

Link to comment
https://forums.phpfreaks.com/topic/54219-reading-xml-with-php/
Share on other sites

Hi

 

This worked for me using PHP5:

 

<?php
$file = "<PropertyURL>http://developer.newcondosonline.com/direct1.php?property=1568&amp;pname=The Potrero&amp;compid=626</PropertyURL>";
$xml = simplexml_load_string($file);
print_r($xml);
?>

 

The output is:

 

SimpleXMLElement Object ( [0] => http://developer.newcondosonline.com/direct1.php?property=1568&pname=The Potrero&compid=626 ) 

 

You would need to use simplexml_load_file as it is an external file.  See http://www.php.net/manual/en/ref.simplexml.php for more info.

 

Link to comment
https://forums.phpfreaks.com/topic/54219-reading-xml-with-php/#findComment-268807
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.