Forked from phpfiddle/19c763e8e5d37d254c5f98549b3ddb64.php
Created
August 27, 2014 11:05
-
-
Save cyberwani/f8010bb91e390c5224fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * | |
| * cURL and XML parsing. | |
| * | |
| */ | |
| $url = "http://www.w3schools.com/xml/simple.xml"; | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); | |
| $content = curl_exec($ch); | |
| curl_close($ch); | |
| $xml = simplexml_load_string($content); | |
| $results = $xml->xpath('/breakfast_menu/food'); | |
| foreach($results as $result) | |
| { | |
| echo "Name : " . $result->name . "<br />"; | |
| echo "Description : " . $result->name . "<br />"; | |
| echo "Price : " . $result->price . ", Calories : " . $result->calories . "<br /><br />"; | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * cURL and XML parsing | |
| * | |
| */ | |
| $url = "http://www.w3schools.com/xml/simple.xml"; | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); | |
| $content = curl_exec($ch); | |
| curl_close($ch); | |
| $xml = simplexml_load_string($content); | |
| $results = $xml->xpath('/breakfast_menu/food'); | |
| foreach($results as $result) | |
| { | |
| echo "Name : " . $result->name . "<br />"; | |
| echo "Description : " . $result->name . "<br />"; | |
| echo "Price : " . $result->price . ", Calories : " . $result->calories . "<br /><br />"; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment