piyush23424 Posted November 18, 2010 Share Posted November 18, 2010 hi, i am requesting bookrenter.com with curl and getting back a response in something like xml format The response is <response> <book> <info> <isbn13>9780324786453</isbn13> <isbn10>032478645X</isbn10> </info> <prices> <rental_price days="45">$17.43</rental_price> <rental_price days="90">$24.35</rental_price> <rental_price days="60">$20.87</rental_price> <rental_price days="30">$15.87</rental_price> <rental_price days="125">$28.99</rental_price> </prices> <lowest_shipping_price>$0.00</lowest_shipping_price> <availability>In Stock</availability> <url>http://www.shareasale.com/r.cfm?u=&b=96706&m=14293&urllink=www.bookrenter.com%2Fdiscovering-computers-2010-living-in-a-digital-world-complete-shelly-cashman-series-032478645X-9780324786453</url> </book> </response> Now i want to process the response so that it will show the values in user readable form like 45 day's rent is $17.43 90 day's rent is $24.35 60 day's rent is $20.87 30 day's rent is $15.87 125 day's rent is $28.99 Shipping price is $0.00 plz help Thanks Link to comment https://forums.phpfreaks.com/topic/219058-how-to-read-xml-with-php/ Share on other sites More sharing options...
trq Posted November 18, 2010 Share Posted November 18, 2010 simplexml. Link to comment https://forums.phpfreaks.com/topic/219058-how-to-read-xml-with-php/#findComment-1136014 Share on other sites More sharing options...
Barand Posted November 18, 2010 Share Posted November 18, 2010 <?php $str = <<< XML <response> <book> <info> <isbn13>9780324786453</isbn13> <isbn10>032478645X</isbn10> </info> <prices> <rental_price days="45">$17.43</rental_price> <rental_price days="90">$24.35</rental_price> <rental_price days="60">$20.87</rental_price> <rental_price days="30">$15.87</rental_price> <rental_price days="125">$28.99</rental_price> </prices> <lowest_shipping_price>$0.00</lowest_shipping_price> <availability>In Stock</availability> <url> http://www.shareasale.com/r.cfm?u=&b=96706&m=14293&urllink=www.bookrenter.com%2Fdiscovering-computers-2010-living-in-a-digital-world-complete-shelly-cashman-series-032478645X-9780324786453 </url> </book> </response> XML; $xml = simplexml_load_string($str); foreach ($xml->book->prices->rental_price as $p) { echo "{$p['days']} day's rent is $p<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/219058-how-to-read-xml-with-php/#findComment-1136015 Share on other sites More sharing options...
ignace Posted November 18, 2010 Share Posted November 18, 2010 SimpleXML has the habbit of choking on semi-big files so if you experience time-out's when reading in the XML use XMLReader instead which uses pull-parsing. Link to comment https://forums.phpfreaks.com/topic/219058-how-to-read-xml-with-php/#findComment-1136028 Share on other sites More sharing options...
piyush23424 Posted November 19, 2010 Author Share Posted November 19, 2010 Thanks Barand and ..... thanks for solving my problem. You guys are just great Link to comment https://forums.phpfreaks.com/topic/219058-how-to-read-xml-with-php/#findComment-1136933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.