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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:25:41+00:00 2026-05-11T15:25:41+00:00

If I have a string like: <p>&nbsp;</p> <p></p> <p class=a><br /></p> <p class=b>&nbsp;</p> <p>blah

  • 0

If I have a string like:

<p>&nbsp;</p> <p></p> <p class='a'><br /></p> <p class='b'>&nbsp;</p> <p>blah blah blah this is some real content</p> <p>&nbsp;</p> <p></p> <p class='a'><br /></p> 

How can I turn it into just:

<p>blah blah blah this is some real content</p> 

The regex needs to pick up &nbsp;s and spaces.

  • 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. 2026-05-11T15:25:42+00:00Added an answer on May 11, 2026 at 3:25 pm
    $result = preg_replace('#<p[^>]*>(\s|&nbsp;?)*</p>#', '', $input);

    This doesn’t catch literal nbsp characters in the output, but that’s very rare to see.

    Since you’re dealing with HTML, if this is user-input I might suggest using HTML Purifier, which will also deal with XSS vulnerabilities. The configuration setting you want there to remove empty p tags is %AutoFormat.RemoveEmpty.

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

Sidebar

Related Questions

I have a string that looks something like this: Bürstner &nbsp;&nbsp; When I use
I have a JS stirng like this &lt;div id=grouplogo_nav&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ul&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;li&gt;&lt;a class=group_hlfppt target=_blank href=http://www.hlfppt.org/&gt;&amp;nbsp;&lt;/a&gt;&lt;/li&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
I have a url string like this: http://www.google.com/cse?cx=017840637368510444960:ny1lmky7r-0&client=google-csbe&output=xml_no_dtd&q=simon+g I need to send this url
I have string like this : <input name=my_name id=my_id value=my_value class=my_class /> I would
I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
I have a string like so: var x = as dsa sad asd &nbsp;
I have this string: <td align=right><span>&nbsp;19:45&nbsp;</span></td> I want to use a NSPredicate on it
Let's presume that I have string like '=&?/;#+%' to be a part of my
I have a string like so: http://www.youtube.com/v/Nnp82q3b844&hl=en_US&fs=1& and I want to extract the Nnp82q3b844
Hi guys i have the following string &|L1|L2|L3|& I would like to extract L1

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.