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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:56:17+00:00 2026-05-20T17:56:17+00:00

There is probably a very simple answer to this, but I want to be

  • 0

There is probably a very simple answer to this, but I want to be as detailed as possible so that you do not need me to clarify.

I am trying to collect the contents of every

<content><div>CONTENT</div></content>

The content needs to be returned as a backreference ($1). Both the content and the div have differing parameters (such as style="color: white;"). These parameters are unimportant, but exist nonetheless.

The complication is that the div may contain child div’s. These are not important, but conflict with my current regex – stopping the match early.

Here is a sample of the code, imagine this copy/pasted several times and formatted differently.

<entry> 
<title>A general title of a post</title> 
<content type="xhtml"> 
    <div xmlns="http://www.w3.org/1999/xhtml"> 
    This is a description of the title. It may <b>contain bold text</b> or <div>even divs</div>, and everything else. It is not quite important to save these tags, but they exist nonetheless.
    </div> 
</content> 
</entry>

Currently, I am using two regex codes. One for the declaration, and one for the closing tags. This works, but now I need to execute code on the contents. So, I will use preg_replace_callback(), but I can’t figure out how to connect the two so that the middle is a callback.

Declaration:

<content \w+\s*=\s*\".*?\">[\r\n\s]{0,}<div \w+\s*=\s*\".*?\">

Closing:

</div>[\r\n\s]{0,}</content>

I need these combined, with the contents returned as a callback. I have tried something like ([\w\W]{0,}), which returns absolutely everything, but this match doesn’t stop at the closing div.

So I found out about the \bFULLWORD\b command, and threw \bdiv\b on that… But I have had no success getting that to work. Perhaps it is not supported by PHP? Or I am stupid.

I do not know.

Please help!

  • 1 1 Answer
  • 1 View
  • 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-20T17:56:17+00:00Added an answer on May 20, 2026 at 5:56 pm

    Use a DOM parser. Here’s an example: http://htmlparsing.com/php.html

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

Sidebar

Related Questions

There is probably a very simple answer to this question, but I can't for
This is probably a very simple answer, but I'm not seeing an obvious solution
there is probably a very simple answer to this very simple question, but i
There is probably already an answer for this somewhere, but I must not be
There is probably a simple answer for this, but I couldn't find one, so
I feel like the answer to this question is probably very simple, but I'm
All, This question probably has a very simple answer - something I'm overlooking. But
This is probably very simple, but I simply cannot find the answer myself :(
There is probably a very simple way of doing this, but this is a
Sorry, I'm new to Java and there's probably a very simple answer to this.

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.