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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:13:54+00:00 2026-05-13T00:13:54+00:00

i am using DOM to get content of div tag but inner html part

  • 0

i am using DOM to get content of div tag but inner html part is not shown.
Function is:

$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTMLFile("$url");
libxml_use_internal_errors(false);
$xpath = new DOMXPath($dom);
$divTag = $xpath->query('//div[@id="post"]');
foreach ($divTag as $val) {
echo $val->getAttribute('title') . ' - ' . $val->nodeValue . "<br />\n";
}

if source of page is (just for Div)

<div id="post">Some text <img src="..." /> <table>some codes</table></div>

then function returns just

"Some text " 

but i want to get all HTML elements too, like that:

Some text <img src="..." /> <table>some codes</table>

Is there any way to do it? Thanks right now.

  • 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-13T00:13:55+00:00Added an answer on May 13, 2026 at 12:13 am

    If you’re looking for the DOMDocument version of innerHTML in the browser DOM, the nearest is saveXML.

    echo $dom->saveXML(val).'<br />\n';
    

    (Remember to htmlspecialchars if you want that to actually appear as text.)

    This gives you the outerHTML though. If you really need the innerHTML, you’d have to loop through each of the element’s child nodes and pass them to saveXML, then implode them.

    And it’s XML serialisation only: there is no corresponding HTML version. saveHTML does exist but can only save the whole document at once, sadly. If it matters that you get legacy-HTML, you might be able to get away with it by passing in the LIBXML_NOEMPTYTAG option to ensure that annoying empty tags like <script src="..."></script> don’t break the browser.

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

Sidebar

Related Questions

I am trying to get the specific tag content, but seems I am not
Using HTML 5 together with the DOM is there a way to get the
I'm using PHP/Zend to load html into a DOM, and then I get a
After load content to page using div.load('page.php'); I need get all of links from
If content is added to the DOM using, e.g., $(ul).append(<li>test</li>); how does one get
Using jQuery I can easily get the number of DOM elements used by a
I am using DOM parser to parse xml data, but its taking lots of
I'm using DOM PDF to convert a simple html page to a PDF--everything works
i am creating div using DOM Element as phototab = document.createElement('div'); phototab.setAttribute('class', 'phototab fleft');
I want to parse the xml file with dynamic content using DOM parser in

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.