want a variable from xml file

this is an xml file by going to a browser and typing in a url and apiKey=xxxx

<body>Don't forget me this weekend!</body>

how can I just echo $heading=Jani
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are you willing to parse an XML file with PHP to get some variables?
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 :
Amar BardoliwalaCommented:

I was able to display nodes using following code.


$xml = "<note>
<body>Don't forget me this weekend!</body>

//Create object of SimpleXML
$obj = SimpleXML_Load_String($xml);

print "to = " . (string)$obj->to;
print "<br/>from = " . (string)$obj->from;
print "<br/>heading = " . (string)$obj->heading;
print "<br/>body = " . (string)$obj->body;


Open in new window

Please look at above code to see if it helps you.

Thank You.

Amar Bardoliwala

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PHP is case sensitive... you need to replace line 13 with:

$obj = simplexml_load_string($xml);

Open in new window

..but otherwise, I'd say that's your best bet!
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

rgb192Author Commented:
your code sample works using $xml variable
but what if the code is coming from another website.

how can I capture that data
Amar BardoliwalaCommented:
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



Hope this will you.

Thank You.

Amar Bardoliwala
rgb192Author Commented:

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
    return $output;

Open in new window

Amar BardoliwalaCommented:

you need to assign $output to $xml as following.

$xml = curl_download($Url);

Hope this will help you.

Thank You.

Amar Bardoliwala.

Ray PaseurCommented:
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.

to = Tove
from = Jani
heading = Reminder
body = Don't forget me this weekend!

Best regards to all, ~Ray
rgb192Author Commented:
this works for the question, thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.