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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:12:50+00:00 2026-06-14T00:12:50+00:00

I have content that is being outputted via WordPress, and it wraps paragraph <p>

  • 0

I have content that is being outputted via WordPress, and it wraps paragraph <p> tags around the content. I need to remove the content within the first <p></p> .. How can I do this?

For example, output is:

<p>Posted by Bob</p>
<p>This is the content here</p>
<p>This is the second paragraph</p>

I’d like to remove the line <p>Posted by Bob</p> and leave the rest.

  • 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-14T00:12:52+00:00Added an answer on June 14, 2026 at 12:12 am

    Generally, you should not parse HTML with regex.

    In this case, a regex solution might work fine though:

    $str = preg_replace('~<p>.*?</p>~s', '', $str, 1);
    

    The important things are

    • the ? which makes the .* ungreedy (so that it stop as soon as possible and does not continue until the very last </p>
    • the modifier s so that . is able to match new-lines
    • the limit 1 so that only the first match is removed

    If you only want to remove the contents of the tag (so if you want to keep an empty paragraph), simply use <p></p> as the replacement string.

    However, as I said this is still not a perfect solution. Think about <p> tags in comments, or <p> tags that have attributes or even invalid HTML. PHP comes with a DOM parser. If you can use 3rd-party libraries there is also this one, which is quite convenient to use and makes the problem almost trivial:

    require "simple_html_dom.php";
    
    $html = new simple_html_dom($input);
    $html->load($input);
    
    $html->find('p', 0)->outertext = "";
    
    $output = $html->save();
    

    Equally if you just want to empty the tag, but keep it, replace outertext with innertext.

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

Sidebar

Related Questions

I have content that is being dynamically generated. How to I listen to a
I have blocks of content that are toggled on/off via jQuery and I want
I have a rails application that displays content that is being rendered as a
I have some content that, for some reason, is not being shown in IE8
I have an XML document that's being generated from some content that people are
I have a simple list of images that is being controlled via a CMS
I have a page ( somePage.aspx ) and I need the content that has
I have some content that I want to appear on multiple pages of my
I have some content that I am loading using jquery ajax. The content has
Hey guys I simply cannot get this to work. I have some content that

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.