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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:58:30+00:00 2026-05-25T02:58:30+00:00

here is a code: <?php $html = <<< HTML <div id=one> <h1>header 1</h1> <h2>header

  • 0

here is a code:

<?php
$html = <<< HTML
    <div id="one">
<h1>header 1</h1>
<h2>header 2</h2>
<blockquote>
    <p>paragraph1</p>
    <p>paragraph2</p>
</blockquote>
    <b>bold text1</b>
<b>bold text2</b>
</div>
HTML;



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

/******************3rd part*************/
     echo $dom->childNodes->item(0)->nodeName."<br>";
 echo $dom->childNodes->item(1)->nodeName."<br>";


    /**********1st part**********/
$tags = $dom->getElementsByTagName("blockquote");
foreach($tags as $tag)
{
    $ps=$tag->getElementsByTagName("p");
    foreach($ps as $p)
    {
        echo $p->nodeValue."<br>";
    }
}

/************2nd part**********/
$tags = $dom->getElementById("one");
foreach($tags as $tag)
{
    $hs=$tag->getElementsByTagName("h1");
    foreach($hs as $h)
    {
        echo $h->nodeValue."<br>";
    }
}

?>

Please teach me by example :

  1. What is the firstNode and lastNode in $html? How can I print the text inside those nodes?
  2. Why the second part of the code prints nothing ?
  3. <h2>header 2</h2> is this a single node ?
  4. What is the difference between textContet and nodeValue ?
  5. What is the idea of textContent, item() and childnodes?
  6. How many child odes does div#one contain?
  7. Which are the childNodes of $dom? How can I print their names?
  8. What is the error in the 3rd part of this code? Both lines are showing the same!

I have read @Gordon’s answer from here but I need some clear examples.

  • 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-25T02:58:31+00:00Added an answer on May 25, 2026 at 2:58 am
    1. both are <div id="one"> Note the all the h1, h2 and blockquote nodes are childs of this one.
    2. $dom->getElementById(0); would return the first element. $dom->getElementById(1); would return the second (if it existed) id is the name of an attribute in this tag <div id="one">
    3. Do not understand the question. what do you mean by single node?
    4. textContent: all the texts within the childNodes (http://www.w3schools.com/dom/prop_element_textcontent.asp); nodeValue: value of a node, depending on its type http://www.w3schools.com/dom/prop_document_nodevalue.asp
    5. read on … this http://www.w3schools.com/htmldom/default.asp

    I leave the rest to other SO users.

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

Sidebar

Related Questions

Here's my code for registerFormOne.php : <html> <head> <title>Registration Form - 1 of 2</title>
Here is my code <html> <body> <?php echo <b>Hello World</b> <br />; ?> </body>
Here is my code : function search_buddy() { $.post(num.php,function (ret){ num=ret; }); $(#Layer7).html(num); }
Here is my PHP code.. $input = zergling-light $output = str_replace('-', ' (', $input).);
here is my mysql and php code layout: I have 3 tables tableA stores
So I have some PHP code that looks like: $message = 'Here is the
Here is the code I dont know whats wrong with it. <?php //Logout code
For example, my goal is to test the code given here: PHP script that
here is the code <php? $id1 =1; $id2 = module 1 loaded; echo $var1=$id1,$var2=$id2;
Here's the code: <?php class Order extends Zend_Db_Table_Abstract { protected $_name = 'orders'; protected

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.