Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing XML using PHP and displaying result in browser
    text
    copied!<p>i'm working on an xml file that i'm trying to parse in php and display it on the browser..here's a bit of my code </p> <pre><code>&lt;?php $myurl = "http://localhost/masterclass/xml/REA_2013-09-18-13_31_48.xml"; $curl = curl_init($myurl); curl_setopt($curl, CURLOPT_FAILONERROR, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($curl); $xmldata = simplexml_load_string($result); foreach ($xmldata-&gt;residential-&gt;objects-&gt;img as $img){ $attrib = $img-&gt;attributes(); var_dump($attrib['url']); } ?&gt; </code></pre> <p>When i run the above, i get the following result..</p> <pre><code>object(SimpleXMLElement)#16 (1) { [0]=&gt; string(66) "http://assets.boxdice.com.au /one_agency/listings/2912/9e605516.jpg" } object(SimpleXMLElement)#15 (1) { [0]=&gt; string(66) "http://assets.boxdice.com.au/one_agency/listings/2912/5cdc8604.jpg" } object(SimpleXMLElement)#14 (1) { [0]=&gt; string(66) "http://assets.boxdice.com.au /one_agency "http://assets.boxdice.com.au/one_agency/listings/2912/45e59869.jpg" } object(SimpleXMLElement)#16 (1) { [0]=&gt; string(66) "http://assets.boxdice.com.au /one_agency /listings/2912/aca74229.jpg" } NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL </code></pre> <p>I need help to extract the url's and stop the loop from returning NULL</p> <p>here's the xml file</p> <pre><code>&lt;propertyList username="oneagen0" date="2013-09-18-13:01:14" password="maryanne"&gt; &lt;residential status="current" modTime="2013-09-18-13:01:14"&gt; &lt;priceView&gt; &lt;![CDATA[Offers Over $535,000]]&gt; &lt;/priceView&gt; &lt;listingAgent id="1"&gt; &lt;name&gt;Anita Ellis-Case&lt;/name&gt; &lt;email&gt;anitaec@oneagency.com.au&lt;/email&gt; &lt;telephone type="BH"&gt;0243812004&lt;/telephone&gt; &lt;telephone type="mobile"&gt;0412996488&lt;/telephone&gt; &lt;/listingAgent&gt; &lt;address display="yes"&gt; &lt;streetNumber&gt;145&lt;/streetNumber&gt; &lt;street&gt;Del Monte Place&lt;/street&gt; &lt;suburb display="yes"&gt;COPACABANA&lt;/suburb&gt; &lt;state&gt;NSW&lt;/state&gt; &lt;postcode&gt;2251&lt;/postcode&gt; &lt;country&gt;Australia&lt;/country&gt; &lt;/address&gt; &lt;objects&gt; &lt;img format="jpg" url="http://assets.boxdice.com.au/one_agency/listings /2912/9e605516.jpg" id="m" modTime="2013-09-18-13:01:14"/&gt; &lt;img format="jpg" url="http://assets.boxdice.com.au/one_agency/listings /2912/5cdc8604.jpg" id="a" modTime="2013-09-18-13:01:14"/&gt; &lt;img format="jpg" url="http://assets.boxdice.com.au/one_agency/listings/2912/e0374768.jpg" id="b" modTime="2013-09-18-13:01:14"/&gt; &lt;img format="jpg" url="http://assets.boxdice.com.au/one_agency/listings/2912/45e59869.jpg" id="c" modTime="2013-09-18-13:01:14"/&gt; &lt;img format="jpg" url="http://assets.boxdice.com.au/one_agency/listings/2912/aca74229.jpg" id="d" modTime="2013-09-18-13:01:14"/&gt; &lt;img id="e"/&gt; &lt;img id="f"/&gt; &lt;img id="g"/&gt; &lt;img id="h"/&gt; &lt;img id="i"/&gt; &lt;img id="j"/&gt; &lt;img id="k"/&gt; &lt;img id="l"/&gt; &lt;img id="n"/&gt; &lt;img id="o"/&gt; &lt;img id="p"/&gt; &lt;img id="q"/&gt; &lt;img id="r"/&gt; &lt;img id="s"/&gt; &lt;img id="t"/&gt; &lt;img id="u"/&gt; &lt;img id="v"/&gt; &lt;img id="w"/&gt; &lt;img id="x"/&gt; &lt;img id="y"/&gt; &lt;img id="z"/&gt; &lt;floorplan id="1"/&gt; &lt;floorplan id="2"/&gt; &lt;/objects&gt; &lt;agentID&gt;ELLISCASE01&lt;/agentID&gt; &lt;uniqueID&gt;OneAgency_1_2912&lt;/uniqueID&gt; &lt;headline&gt;Oceanfront headland position- 600m to the sand&lt;/headline&gt; &lt;description&gt; &lt;![CDATA[Being offered for sale for the first time, this cliff top property offers one of the last remaining opportunities to knock down/ rebuild in this exclusive set of properties. Remaining in the one family for many years and used as a weekender, the owner is giving one lucky buyer the opportunity to make their own happy memories. -Three standard bedrooms, main with built in robes -Central bathroom with bath for children and separate WC -Dining area off kitchen with back deck access and to rear reserve -Downstairs poses flexible uses- either bedroom with ensuite or at home office -Undercover parking -Private position with valley views to the front -Ocean views from the rear, walk to the beach and look out]]&gt; &lt;/description&gt; &lt;authority value="exclusive"/&gt; &lt;category name="House"/&gt; &lt;underOffer value="no"/&gt; &lt;price display="yes"&gt;475000.0&lt;/price&gt; &lt;features&gt; &lt;bathrooms&gt;2&lt;/bathrooms&gt; &lt;bedrooms&gt;4&lt;/bedrooms&gt; &lt;carports&gt;1&lt;/carports&gt; &lt;ensuite&gt;0&lt;/ensuite&gt; &lt;remoteGarage&gt;0&lt;/remoteGarage&gt; &lt;secureParking&gt;0&lt;/secureParking&gt; &lt;airConditioning&gt;0&lt;/airConditioning&gt; &lt;alarmSystem&gt;0&lt;/alarmSystem&gt; &lt;vacuumSystem&gt;0&lt;/vacuumSystem&gt; &lt;intercom&gt;0&lt;/intercom&gt; &lt;poolInGround&gt;0&lt;/poolInGround&gt; &lt;poolAboveGround&gt;0&lt;/poolAboveGround&gt; &lt;tennisCourt&gt;0&lt;/tennisCourt&gt; &lt;balcony&gt;1&lt;/balcony&gt; &lt;deck&gt;0&lt;/deck&gt; &lt;courtyard&gt;0&lt;/courtyard&gt; &lt;outdoorEnt&gt;0&lt;/outdoorEnt&gt; &lt;shed&gt;0&lt;/shed&gt; &lt;fullyFenced&gt;0&lt;/fullyFenced&gt; &lt;openFirePlace&gt;0&lt;/openFirePlace&gt; &lt;toilets&gt;0&lt;/toilets&gt; &lt;livingAreas&gt;0&lt;/livingAreas&gt; &lt;insideSpa&gt;0&lt;/insideSpa&gt; &lt;outsideSpa&gt;0&lt;/outsideSpa&gt; &lt;broadband&gt;0&lt;/broadband&gt; &lt;builtInRobes&gt;0&lt;/builtInRobes&gt; &lt;dishwasher&gt;0&lt;/dishwasher&gt; &lt;ductedCooling&gt;0&lt;/ductedCooling&gt; &lt;ductedHeating&gt;0&lt;/ductedHeating&gt; &lt;evaporativeCooling&gt;0&lt;/evaporativeCooling&gt; &lt;floorboards&gt;0&lt;/floorboards&gt; &lt;gasHeating&gt;0&lt;/gasHeating&gt; &lt;gym&gt;0&lt;/gym&gt; &lt;hydronicHeating&gt;0&lt;/hydronicHeating&gt; &lt;payTV&gt;0&lt;/payTV&gt; &lt;reverseCycleAirCon&gt;0&lt;/reverseCycleAirCon&gt; &lt;rumpusRoom&gt;0&lt;/rumpusRoom&gt; &lt;splitSystemAirCon&gt;0&lt;/splitSystemAirCon&gt; &lt;splitSystemHeating&gt;0&lt;/splitSystemHeating&gt; &lt;study&gt;0&lt;/study&gt; &lt;workshop&gt;0&lt;/workshop&gt; &lt;otherFeatures&gt;Balcony&lt;/otherFeatures&gt; &lt;/features&gt; &lt;landDetails&gt; &lt;area of="total" unit="squareMeter"&gt;746.0&lt;/area&gt; &lt;/landDetails&gt; &lt;videoLink href="http://animoto.com/play/Cd5Q7zQmFbAlfRwDN4DTeQ"/&gt; &lt;/residential&gt; &lt;/propertyList&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload