Guest Posted March 3, 2013 Share Posted March 3, 2013 I wrote a script to check a remote xml file for the stock state of some products. I want to list all sizes ID having "available"=true and "appearance id"=2 the expected result should be 23456 but i'm getting 3823456 where the hell does this "38" comes from ? Here's the script: <?php $checkstockcolor = "2"; $apiurl = "http://api.spreadshirt.com/api/v1/shops/266497/productTypes/175"; $feed = simplexml_load_file($apiurl); $producttype = $feed->productType; $stockstate = $feed->stockStates->stockState; foreach ($stockstate as $stock) { $available = $stock->available; $stockcolor = $stock->appearance[id]; $size = $stock->size[id]; // garder uniquement les résultats de la couleur présentement sélectionnée if ($stockcolor == $checkstockcolor && $available == "true") { echo "$size<br>"; } } ?> Thank you ! Link to comment https://forums.phpfreaks.com/topic/275142-simplexml-problem/ Share on other sites More sharing options...
requinix Posted March 3, 2013 Share Posted March 3, 2013 true999From there. Link to comment https://forums.phpfreaks.com/topic/275142-simplexml-problem/#findComment-1416114 Share on other sites More sharing options...
us2rn4m2 Posted March 3, 2013 Share Posted March 3, 2013 echo $feed->sizes->size[5]['id']; // 38 Link to comment https://forums.phpfreaks.com/topic/275142-simplexml-problem/#findComment-1416133 Share on other sites More sharing options...
Guest Posted March 3, 2013 Share Posted March 3, 2013 Weird... my browser didn't find any results when i was searching for "38" in the XML file.... Sorry about the dumb question then... Link to comment https://forums.phpfreaks.com/topic/275142-simplexml-problem/#findComment-1416234 Share on other sites More sharing options...
requinix Posted March 3, 2013 Share Posted March 3, 2013 It's a large XML file. You may have tried searching before it was fully downloaded. Link to comment https://forums.phpfreaks.com/topic/275142-simplexml-problem/#findComment-1416302 Share on other sites More sharing options...
sKunKbad Posted March 4, 2013 Share Posted March 4, 2013 I've got a simplexml "cheat sheet" that I keep handy because I've done a lot of work with XML. Last week, or maybe the week before, I turned the info into a blog post on my website. Here is a link to the blog post: http://bit.ly/W4QWpf The blog post goes over just about all of your potential parsing needs. Namespaces, attributes, etc. Link to comment https://forums.phpfreaks.com/topic/275142-simplexml-problem/#findComment-1416396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.