rgb192
asked on
want a variable from xml file
this is an xml file by going to a browser and typing in a url and apiKey=xxxx
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading >
<body>Don't forget me this weekend!</body>
</note>
how can I just echo $heading=Jani
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading
<body>Don't forget me this weekend!</body>
</note>
how can I just echo $heading=Jani
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PHP is case sensitive... you need to replace line 13 with:
..but otherwise, I'd say that's your best bet!
$obj = simplexml_load_string($xml);
..but otherwise, I'd say that's your best bet!
ASKER
your code sample works using $xml variable
but what if the code is coming from another website.
how can I capture that data
but what if the code is coming from another website.
how can I capture that data
Hello rgb192,
you did not tell that you want to capture data from another site...
But you can capture data using CURL for php
Following are some links from which you will get help for curl
http://php.net/manual/en/curl.examples.php
http://www.jonasjohn.de/snippets/php/curl-example.htm
Hope this will you.
Thank You.
Amar Bardoliwala
you did not tell that you want to capture data from another site...
But you can capture data using CURL for php
Following are some links from which you will get help for curl
http://php.net/manual/en/curl.examples.php
http://www.jonasjohn.de/snippets/php/curl-example.htm
Hope this will you.
Thank You.
Amar Bardoliwala
ASKER
http://www.jonasjohn.de/snippets/php/curl-example.htm
how can I call this output $xml
how can I call this output $xml
function curl_download($Url){
// is cURL installed yet?
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $Url);
// Set a referer
curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
// User agent
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
return $output;
}
Hello
you need to assign $output to $xml as following.
$xml = curl_download($Url);
Hope this will help you.
Thank You.
Amar Bardoliwala.
you need to assign $output to $xml as following.
$xml = curl_download($Url);
Hope this will help you.
Thank You.
Amar Bardoliwala.
Regarding this: PHP is case sensitive...
True for variables.
$x != $X
False for class and function names.
SimpleXML_Load_String() == simplexml_LOAD_stRinG()
The script at ID:37379877 works perfectly. I copied it, installed it and tested it here.
http://www.laprbass.com/RAY_temp_amar.php
Outputs:
to = Tove
from = Jani
heading = Reminder
body = Don't forget me this weekend!
Best regards to all, ~Ray
True for variables.
$x != $X
False for class and function names.
SimpleXML_Load_String() == simplexml_LOAD_stRinG()
The script at ID:37379877 works perfectly. I copied it, installed it and tested it here.
http://www.laprbass.com/RAY_temp_amar.php
Outputs:
to = Tove
from = Jani
heading = Reminder
body = Don't forget me this weekend!
Best regards to all, ~Ray
ASKER
this works for the question, thank you
If that's what you want to do, you need to use some XML API to parse the xml file.
For exemple you can check :
http://www.php.net/manual/en/book.dom.php