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 8992151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:53:19+00:00 2026-06-15T22:53:19+00:00

As I have mentioned in question title, I am trying below code to reach

  • 0

As I have mentioned in question title, I am trying below code to reach till the desired node in xpath result.

<?php
$xpath = '//*[@id="topsection"]/div[3]/div[2]/div[1]/div/div[1]';          
$html = new DOMDocument();
@$html->loadHTMLFile('http://www.flipkart.com/samsung-galaxy-ace-s5830/p/itmdfndpgz4nbuft');
$xml = simplexml_import_dom($html);   
if (!$xml) {
    echo 'Error while parsing the document';
    exit;
}

$source = $xml->xpath($xpath);
echo "<pre>";
print_r($source);
?>

this is the source code. I am using to scrap price from a ecommerce.
it works it gives below output :

Array
(
    [0] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [class] => line
                )

            [div] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [class] => prices
                            [itemprop] => offers
                            [itemscope] => 
                            [itemtype] => http://schema.org/Offer
                        )

                    [span] =>  Rs. 10300
                    [div] => (Prices inclusive of taxes)
                    [meta] => Array
                        (
                            [0] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [itemprop] => price
                                            [content] => Rs. 10300
                                        )

                                )

                            [1] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [itemprop] => priceCurrency
                                            [content] => INR
                                        )

                                )

                        )

                )

        )

)

Now How to reach till directly [content] => Rs. 10300.
I tried:

echo $source[0]['div']['meta']['@attributes']['content']

but it doesn’t work.

  • 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-06-15T22:53:20+00:00Added an answer on June 15, 2026 at 10:53 pm

    The print_r of a SimpleXMLElement does not show the real object structure. So you need to have some knowledge:

    $source[0]->div->meta['content']
            |    |     |      `- attribute acccess
            |    |     `- element access, defaults to the first one
            |    `- element access, defaults to the first one
            |
     standard array access to get 
     the first SimpleXMLElement of xpath()
     operation
    

    That example then is (with your address) the following (print_r again, Demo):

    SimpleXMLElement Object
    (
        [0] => Rs. 10300
    )
    

    Cast it to string in case you want the text-value:

    $rs = (string) $source[0]->div->meta['content'];
    

    However you can already directly access that node with the xpath expression (if that is a single case).

    Learn more on how to access a SimpleXMLElement in the Basic SimpleXML usage ExamplesDocs.

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

Sidebar

Related Questions

Some people have mentioned RockScroll and MetaScroll in This Question , but those only
As I have mentioned in the title, my dispatch_async is firing 10 times. And
I have a C++ array declared as mentioned below: CString carray[] = { A,
I have a simple requirement as mentioned below: A ListView or any control displays
I have been trying my hand at php for quite some time but dont
Sorry for the vague thread title; hard to succinctly describe my question. I have
UPDATE: I should have mentioned in the original post that I want to learn
Im facing following problem I have created mentioned condition, but when I choose y
I am working with images, they all have their sizes mentioned in their name
I have tried many options mentioned in the previous messages/forums.None of them seem to

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.