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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:35:33+00:00 2026-06-13T22:35:33+00:00

Here is a bit of my code… $dom = new DomDocument; $html = $newIDs[0];

  • 0

Here is a bit of my code…

$dom = new DomDocument;
$html = $newIDs[0];
$dom->validateOnParse = true;
$dom->loadHTML($html);
$dom->preserveWhiteSpace = true;
$tryID = $dom->getElementById('ID');
echo $tryID;

I am trying to get multiple specific IDs from a website, this just shows one, and I have seen this method everywhere, including on here, but when I try and print something out nothing shows up. I tried testing to see if it is reading something in with

if(!$tryID)
{
    ("Element not found");
}

But it never prints that out either. Lastly, I have used

echo $tryID->nodeValue;

and still nothing… anyone know what I am doing wrong?

Also, if I do get this working can I read in multiple different things to different variables on the same $dom ? If that makes ay sense.

  • 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-13T22:35:34+00:00Added an answer on June 13, 2026 at 10:35 pm

    Ok, so your solution.

    For a DIV:

    <div id="divID" name="notWorking">This is not working!</div>
    

    This will do:

    <?php
    
        $dom = new DOMDocument("1.0", "utf-8");
        $dom->loadHTMLFile('YourFile.html');
        $div = $dom->getElementById('divID');
    
        echo $div->textContent;
    
        $div->setAttribute("name", "yesItWorks");
    ?>
    

    Should work without the file as long as you pass a Well-Made XML or XHTML content, changing

    $dom->loadHTMLFile('YourFile.html');
    

    to your

    $dom->loadHTML($html);
    

    Oh yeah, and of course, to CHANGE the content (For completeness):

    $div->removeChild($div->firstChild);
    $newText = new DOMText('Yes this works!');
    $div->appendChild($newText);
    

    Then you can just Echo it again or something.

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

Sidebar

Related Questions

i just want to ask about my html code here, i have a bit
Here I have the following bit of code: private IList<IState> _states = new List<IState>();
Here's my bit of code: List<Sale> sales = new List<Sale>(); if (Cache[Sales] != null)
It seems like I had to inline quite a bit of code here. I'm
Here's the relevant bit of the source code: class Dice { String name ;
I have some code here that uses bitsets to store many 1 bit values
I have a little bit of Javascript that almost works correctly. Here's the code:
I am playing around with WPF a bit. Here is the Code that does
Here's my small bit of code. protected void ViewVisio(string url) { // open document
Here's a bit of code that might seem like it would work: #include <cassert>

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.