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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:09:30+00:00 2026-05-30T23:09:30+00:00

OK , here is a html content that i have : <p> …. </p>

  • 0

OK , here is a html content that i have :

<p> .... </p>
<div id="quick_preview">
<p>the contents </p>
</div>

and what i want is :

<p> .... </p>
<div id="quick_preview">
<description>
  <p>the contents </p>
</description>
</div>

i use this routine to find the div and create description tag, but i don’t know how to insert <description> into div before p:

$dom = new DOMDocument;
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$dom->loadHTML($row['body']);
$divs = $dom->getElementsByTagName('div');
foreach($divs as $div)
{
    if ($div->getAttribute( "id" ) == 'quick_preview') {
        $desc_element = $dom->createElement('description');
    }
}
$dom->saveHTMLFile($html)
  • 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-30T23:09:31+00:00Added an answer on May 30, 2026 at 11:09 pm

    This will do what you want:

    $dom = new DOMDocument;
    $dom->formatOutput = true;
    $dom->preserveWhiteSpace = false;
    $dom->loadHTML($row['body']);
    
    $xpath = new DOMXPath($dom);
    
    $divs = $xpath->query('//div[@id="quick_preview"]');
    foreach ($divs as $div)
    {
        $description = $dom->createElement('description');
        while ( $div->hasChildNodes() )
        {
            $description->appendChild($div->firstChild);
        }
        $div->appendChild($description);
    }
    
    $dom->saveHTMLFile($html);
    

    You could drop the XPath and use $dom->getElementById('quick_preview') instead.

    Note that you can move DOM nodes by simply appending them somewhere else in the document.

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

Sidebar

Related Questions

Here is the template that I have been using http://themes.truethemes.net/Karma-HTML/content-pricing-tables.html Here is my test
I want to render content that i have created locally using html component and
Here is my code: $('#right').load('textes.html #nicolas'); $('#right').load('textes.html #antoine'); The problem is that the content
I have some content sliding here. http://www.smallsharptools.com/downloads/jQuery/Slider/slider.html The HTML structure is simple. There is
I have html like so: <div class=foo> (<a href=forum.example.com>forum</a>) <p> Some html here.... </div>
I have a servlet that may return text/html or application/pdf content. Apparently, it looks
I have a folder of static html,imgs,flash content that lives outside of the webapp
I have written some code in PHP that returns the html content from .edu
Here is the input (html, not xml): ... html content ... <tag1> content for
Here is my try: @header(Content-type: text/html; charset=utf-8); @header(Location:/index.php); @header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1 @header(Expires:

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.