Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7308537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:34:15+00:00 2026-05-28T23:34:15+00:00

How do I use PHP to parse XML on the web? Here is the

  • 0

How do I use PHP to parse XML on the web?

Here is the example XML. How would you get the value of the first “AskRealtime”?

I am aware of SimpleXML. I am looking for the proper code to open the XML webpage, and work with it using SimpleXML.

This suggested code does not succesfully load the page:

$xml = @simplexml_load_file("http://query.yahooapis.com/v1/public/yql?q=select%20symbol%2C%20AskRealtime%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22A%22%2C%22AA%22)&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");

$price = $xml->results->quote[0]->AskRealtime;

echo $price;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T23:34:16+00:00Added an answer on May 28, 2026 at 11:34 pm

    Have you tried using SimpleXMLElement? It works just like your code but it’s constructed differently.

    $url = 'http://query.yahooapis.com/v1/public/yql?q=select%20symbol%2C%20AskRealtime%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22A%22%2C%22AA%22)&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys';
    $xml = new SimpleXMLElement($url, null, true);
    echo $xml->results->quote[0]->AskRealtime;
    

    There are different methods for getting the file contents, even though I doubt it’s the problem.

    /* cURL */
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $contents = curl_exec($curl);
    curl_close($curl);
    
    /* Alternative */
    $contents = file_get_contents($url);
    

    Can you tell what is the error you get? Or try var_dump($xml) and see what it returns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I would like to use preg_match in PHP to parse the Desired text
Is it possible to use PHP's SimpleXML functions to create an XML object from
First things first. I know how to parse XML/HTML with simplexml, and I know
How can I parse XML data using PHP? I want to get the contents
I'm trying to use SimpleXML to parse an XML document (an ItemLookupResponse for a
I'm trying to use doxygen to parse php code into xml output. Doxygen does
I'm struggling to parse an XML file in PHP: Here's the XML <rss xmlns:ac=http://palm.com/app.catalog.rss.extensions
I want use php simple xml parse some tree like this. how to plus
At the moment I use PHP for almost everything I develop for the Web
I want to use PHP to replace javascript functions in HTML documents. For example:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.