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

  • Home
  • SEARCH
  • 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 6005267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:22:30+00:00 2026-05-23T01:22:30+00:00

I wonder how I can manipulate the DOM tree using PHP? I have seen

  • 0

I wonder how I can manipulate the DOM tree using PHP?

I have seen some answers with XML DOM that loads in a html file. But what if I don’t need to load? What if have XML DOM scripts inside the document I want to manipulate?

I have an example below that prints out all the folders. Fill in the blanks in your answers. I want to create div-elements with the folder’s name as text node. The answer need to have some XML DOM scripts because I will create more elements than just one div-element in my website. And using for example echo is not practical, because you might insert an element inside the wrong element etc.

$sql = "
    SELECT name
    FROM folders
    WHERE profileId = '$profileId'
";
$result = mysql_query($sql) or die('Error6: '.mysql_error());
while($row = mysql_fetch_array($result)) {

}
  • 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-23T01:22:30+00:00Added an answer on May 23, 2026 at 1:22 am

    You don’t need PHP to manipulate the dom of a document you’re generating already. It’s by far easier to just have PHP directly generate some HTML. DOM’s there to disect/change HTML that was generated elsewhere. In other words, your script would just be:

    while($row = mysql_fetch_array($result)) {
        echo "<div>{$row['name']}</div>";
    }
    

    DOM example, to demonstrate the tediousness

    Ok, here’s the PHP method to generate a paragraph of text with some internal spans and whatnot:

    echo "<div> This is my div, <span>There are many like it, <b>but this one</b> is</span> mine</div>";
    

    The equivalent DOM calls: (not tested, just to demonstrate):

    $dom = new DOM;
    
    $bold = new DOMElement('b');
    $bold->appendChild(new DOMText('but this one'));
    
    $span = new DOMElement('span');
    $span->appendChild(new DOMText('There are many like it,'));
    $span->appendChild($bold);
    $span->appendChild(new DOMText(' is');
    
    $div = new DOMElement('div');
    $div->appendChild(new DOMText(' This is my div,'));
    $div->appendChild($span);
    $div->appendChild(' mine');
    
    echo $div->saveXML();
    

    So……. still thing using DOM is easier than using echo?

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

Sidebar

Related Questions

I wonder if I can test landscape view using simulator?
I always wonder why compilers can't figure out simple things that are obvious to
I am using a DBGrid component in Delphi. I wonder how I can set
I wonder if can I say that a constructor is a special case of
I wonder how can i read a xml data and transform it to a
Hello guys I have a router (Belkin) so I wonder how can I see
I am going to develop ICQ client and I just wonder where can I
I wonder if They can work perfectly together...
I wonder if anyone can provide me with the regular expressions needed to parse
I can only think of Peek() and ReadNoAdvance() atm, but I wonder if there

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.