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

  • Home
  • SEARCH
  • 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 8641279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:29:03+00:00 2026-06-12T11:29:03+00:00

I have a normal paragraph like this: <p>Hey there, I’m a normal paragraph. generated

  • 0

I have a normal paragraph like this:

<p>Hey there, I'm a normal paragraph. generated by a WordPress blog</p>

And I want to change the:

<p> with <h2> and </p> with </h2>

I used str_replace();

$paragraph = array("<p>", "</p>");
$heading2 = array("<h2>","</h2>");
$first_sentence = str_replace($paragraph, $heading2, $first_sentence);

And it should work, but I get this:

<h2>Hey there, I'm a normal paragraph. generated by a WordPress blog<p>/p&gt;</p>

Any ideas why?

  • 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-12T11:29:04+00:00Added an answer on June 12, 2026 at 11:29 am

    You can use Regex for this kind of task:

    $first_sentence = preg_replace('/<p>([^<]+)<\/p>/', '<h2>$1</h2>', $first_sentence);
    

    ([^<]+) means: catch all chars, until < occurs.

    Here you can see it working: http://codepad.viper-7.com/FW1vm5

    But if it gets more complex you should use other techniques (like a DOM parser)

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

Sidebar

Related Questions

I have a WPF RichTextBox control that I want to behave like a normal
I have HTML code like this: <div id=paragraph> <pre> <p>First Line in the paragraph
I have normal sqlite database and want to use fts3. As mentioned in http://www.sqlite.org/fts3.html
I have a normal asp.net page containing some code that I want to measure
Okay let me see if I can explain this right. In wordpress we have
I have normal java installed already. now I want to install a software which
I have some HTML and CSS code like below <html> <head> <style type=text/css> img.normal
Issue I'm planning on making a lightbox-like project page. I want to have it
If you have a paragraph of normal text, you can click anywhere inside the
I have some XML like this: <Section xmlns=\http:schemas.microsoft.com/winfx/2006/xaml/presentation\> <Paragraph FontSize=\12\ FontFamily=\Arial\ Foreground=\#FF000000\ FontWeight=\Normal\ FontStyle=\Normal\

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.