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

The Archive Base Latest Questions

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

Hi everyone I had previously posted about a <br> getting inserted at the beginning

  • 0

Hi everyone I had previously posted about a <br> getting inserted at the beginning of my text and we got that fixed. (here is my previous post with the code) I changed the code as suggested from

$x = preg_replace("/<br>/i","\n",$x);

to

   $x = preg_replace("/^<br(\/|)>/i","\n",$x);

which worked to stop the <br> from being inserted at the beginning but now it is inserting one at the end. How do I stop that from happening?

SOLUTION

$x = preg_replace("/^<br(\/|)>/i","\n",$x);
Jacks solution— //$x = preg_replace('#^<br(\/|)>+|<br(\/|)>+$#i', "\n", $x);
My fix in addition to the original preg_replace

$x= preg_replace("/(^)?(<br\s*\/?>\s*)+$/","\n", $x);

UPDATE

it is no longer adding <br> each time it is submitted but there are now two<br> after the text that only show up in the database and are not brought out in the editor. I need to get rid of these breaks!

  • 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-12T03:29:05+00:00Added an answer on June 12, 2026 at 3:29 am

    This should do it, matches <br>, <br/> or <br /> at the start or end:

    preg_replace('#^<br(\s*/)?>|<br(\s*/)?>$#i', "\n", $str);
    

    The tag is matched by:
    * Literal <br
    * Optional spaces followed by a forward slash

    The | in the middle is used to denote an alternative condition (i.e. OR).

    Edit

    Instead of <br(\s*/)?> you can also write <br(\/|)> that you had before.

    Edit 2

    Multiple occurrences can be matched by just adding + behind each pattern:

    preg_replace('#^<br(\/|)>+|<br(\/|)>+$#i', "\n", $str);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SOLVED. Seriously thank you to everyone that had input. Fantastic community here. I have
everyone! new to here and been pondering about this myself for some times with
I had previously written a function that seems to work, but unfortunately I didn't
Everyone makes a big deal about getting an address from GPS coordinates (reverse geocoding),
I've had a lot of great help from everyone on here. I've been told
Hey everyone, I had a quick question that should be easy for someone who
Hey guys, I've had a lot of help from everyone here and i am
I have searched about this warning and everyone had some mistake in their code,
Everyone, every blog is talking about HTML 5 and giving solution to use HTML
Hey everyone, I had a couple of questions relating to the .NET Entity Framework

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.