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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:47:23+00:00 2026-06-04T03:47:23+00:00

Ok, as it is WordPress problem and it sadly goes a little deeper, I

  • 0

Ok, as it is WordPress problem and it sadly goes a little deeper, I need to remove each representation of parent div and its inside:

<div class="sometestclass">
   <img ....>
   <div>.....</div>
   any other html tags
</div><!-- END: .sometestclass -->

The only idea I have is to match everything that starts with:

<div class="sometestclass">

and ends with:

<!-- END: .sometestclass -->

with all that is between (I can tag the end of parent div anyway I want, this is just a sample).
Anybody have an idea how to do it with:

<?php $content = preg_replace('?????','',$content); ?>
  • 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-04T03:47:25+00:00Added an answer on June 4, 2026 at 3:47 am

    I wouldn’t use a regular expression. Instead, I would use the DOMDocument class. Just find all of the div elements with that class, and remove them from their parent(s):

    $html = "<p>Hello World</p>
             <div class='sometestclass'>
               <img src='foo.png'/>
               <div>Bar</div>
             </div>";
    
    $dom = new DOMDocument;
    $dom->loadHTML( $html );
    
    $xpath = new DOMXPath( $dom );
    $pDivs = $xpath->query(".//div[@class='sometestclass']");
    
    foreach ( $pDivs as $div ) {
      $div->parentNode->removeChild( $div );
    }
    
    echo preg_replace( "/.*<body>(.*)<\/body>.*/s", "$1", $dom->saveHTML() );
    

    Which results in:

    <p>Hello World</p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to repair all the URLs in a Wordpress site. The problem is
Need help with a wordpress problem. I need to edit the query.php to ONLY
i have this problem to my wordpress theme but team points its with Custom
I need to display daily pageviews in my wordpress site. The problem is I
I am currently working on a wordpress theme and I have a little problem
My problem is not with Wordpress's WPDB class, but with the MySQL syntax. I'm
I'm working in Wordpress and need to be able to remove images and empty
Problem: some of the post titles on my WordPress site are questions, i.e. the
Recently installed new wordpress theme. The problem is, there are only following font options
I am coding this layout as a wordpress theme and having a slight problem

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.