Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created July 15, 2014 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phpfiddle/de7b95fc178b9f681768 to your computer and use it in GitHub Desktop.
Save phpfiddle/de7b95fc178b9f681768 to your computer and use it in GitHub Desktop.
[ Posted by Fiddler ] cURL, XML parsing
<?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 />";
}
?>
<?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