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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:13:39+00:00 2026-06-12T13:13:39+00:00

Possible Duplicate: Grabbing the href attribute of an A element I’m currently trying to

  • 0

Possible Duplicate:
Grabbing the href attribute of an A element

I’m currently trying to parse a webpage for a specific element which will be in this format:

<div id="main-id">
    <div id="sub-id-1" onclick="some onclick"> 
    <span class="big-class" style="some style">
    </span>
    <div id="sub-id-2">&#160;</div>
</div>

The main part I’m trying to pull from this is the entire <span class="big-class" style="some style"> tag, as I need to pull the style from the element and store it to a string. To do this, I tried using the following code:

$dom = new DOMDocument();
$dom->validateOnParse = true;
$dom->loadHTML($html);

$belement = $dom->getElementById("main-id");
echo $belement->nodeValue;

However, this is only returning the character Â, which is what the character code &#160 is for.

I’m not really sure what to search for in order to accomplish this, and I’m not even sure if pull entire HTML lines(?) with DOM. Is there any way I could use DOM to return this span element?

  • 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-12T13:13:41+00:00Added an answer on June 12, 2026 at 1:13 pm

    nodeValue will return the innerHTML for your tag. So, in this case it rightly returns Â. You can check PHP Xpath : get all href values that contain needle for a similar discussion. You can do this:

    $html = <<< HTML
    <div id="main-id">
        <div id="sub-id-1" onclick="some onclick"> 
        <span class="big-class" style="some style">
        </span>
        <div id="sub-id-2">&#160;</div>
    </div>
    HTML;
    
    $xml  = simplexml_load_string($html);
    $span_elem = $xml->xpath('//span[@class="big-class"]');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Grabbing the href attribute of an A element I'm trying to extract
Possible Duplicate: Grabbing the href attribute of an A element I need to parse
Possible Duplicate: Grabbing the href attribute of an A element I've gone through a
Possible Duplicate: How to parse HTML with PHP? Grabbing the href attribute of an
Possible Duplicate: Grabbing the href attribute of an A element I would like to
Possible Duplicate: Transparent images with C# WinForms I am coding an app which will
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: How to parse and process HTML with PHP? I am looking for
Possible Duplicate: Parse query string in JavaScript I want to create an options array

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.