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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:23:49+00:00 2026-06-08T07:23:49+00:00

I am after a specific value from a webapge; the product name that is

  • 0

I am after a specific value from a webapge; the product name that is in the h1 tag:

<div id="extendinfo_container">
  <a href="/someproduct.html"><h1><strong>Product Name</strong></h1></a>
  <div style="font-size:0;height:4px;"></div>
  <p class="text_breadcrumbs">
  <a href="/Our-Brands.html" target="_self"><img src="arrow_091.gif" align="absmiddle"/></a>
  <a href="/someproduct.html" target="_self" class="link_breadcrumbs">Product Name</a><img src="arrow_091.gif" align="absmiddle"/>
  <strong>Product Name</strong>
  <div class="dotted_line_blue">
    <img src="theme_shim.gif" height="1" width="100%" alt=" " />
  </div>
</div>

This is a poorly structured website with more than one h1 so I cannot simply do getElementById(‘h1’).

I want to be as specific as possible in which element I get and this is the code I have:

$doc = new DOMDocument();
@$doc->loadHTML(file_get_contents('http://url/to/website'));

// locate <div id="extendinfo_container"><a><h1><strong>(.*)</strong></h1></a> as product name
$x = new DOMXPath($doc);
$pName = $x->query('//div[@id="extendinfo_container"]/a/h1/strong');
var_dump($pName->nodeValue);

This is return null. What query do I need to use to get the content I want?

  • 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-08T07:23:51+00:00Added an answer on June 8, 2026 at 7:23 am

    query() returns a DOMNodeList, which doesn’t have a nodeValue property. You have to select one element (i.e. the first):

    $pName = $x->query('//div[@id="extendinfo_container"]/a/h1/strong')->item(0);
    

    Or iterate over it:

    foreach( $pName as $el) {
        var_dump( $el->nodeValue);
    }
    

    Either one of these will give you access to a DOMNode, which is what you’re looking for.

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

Sidebar

Related Questions

Extracting the href value from the following sample HTML code is straight forward if
Possible Duplicate: selecting items that come after a specific value i asked this allready
I currently have a Generic method that reads an Value from the database based
I want to get a specific value from a resource programmatically. For example, I
I want to assert that a certain registry value exists after installation, so I
I want my app to stop playing video after specific time period (say 30
After eliminating some specific nonsense pattern, I need to identify and possibly delete fields
Example: before: text_before_specific_character(specific_character)text_to_be_deleted after: text_before_specific_character I know that it can be done with sed
What we need: redirect to each user's specific page after their login. What we
After searching the other questions none have answered the specific issue I have. We

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.