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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:38:56+00:00 2026-05-25T09:38:56+00:00

Someone has asked a similar question , but the accepted answer doesn’t meet my

  • 0

Someone has asked a similar question, but the accepted answer doesn’t meet my requirements.

Input:

<strong>bold <br /><br /> text</strong><br /><br /><br />
<a href="#">link</a><br /><br />
<pre>some code</pre>
I'm a single br, <br /> leave me alone.

Expected output:

<p><strong>bold <br /> text</strong><br /></p>
<p><a href="#">link</a><br /></p>
<pre>some code</pre>
<p>I'm a single br, <br /> leave me alone.</p>

The accepted answer I mentioned above will convert multiple br to p, and at last wrap all the input with another p. But in my case, you can’t wrap pre inside a p tag. Can anyone help?

update

the expected output before this edit was a little bit confusing. the whole point is:

  1. convert multiple br to a single one (achieved with preg_replace('/(<br />)+/', '<br />', $str);)

  2. check for inline elements and unwrapped text (there’s no parent element in this case, input is from $_POST) and wrap with <p>, leave block level elements alone.

  • 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-25T09:38:57+00:00Added an answer on May 25, 2026 at 9:38 am

    Alright, I’v got myself an answer, and I believe this is gonna work really well.

    It’s from WordPress…the wpautop function.

    I’v tested it with the input (from my question), and the output is -almost- the same as I expected, I just need to modify it a bit to fit my needs.

    Thanks dare2be, but I’m not very familiar with DOM manipulator in PHP.

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

Sidebar

Related Questions

A similar question has been asked before by someone else , but there were
Someone else has already asked a somewhat similar question: Validate an Xml file against
I know this question has been asked in a similar fashion before, but I
This question has been asked here before . The accepted answer was probably obvious
Probably someone has already asked this question but I'm not sure what I'm looking
Possible Duplicate: Chaining a function in JavaScript? I asked a similar question , but
I have asked a similar question before and got an convincing answer as well?
Sorry if this question has all ready been asked, maybe someone can point me
I asked a similar question but I did not provide sufficient details and I
Someone has already asked, How does the DiggBar work? in a previous question. While

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.