Jump to content

Removing <br>'s at the start of a string only


MyCode

Recommended Posts

Hello,

 

I am looking for a solution to remove one or multiple <br>'s from the start of a string.

 

Example:

 

I am loading a string from my mysql database and the content is:

 

<br><br>This is my string

 

It can be that it's just one <br>, but it could also be three or four <br>'s

 

So what I am looking for is some way to get rid of the <br>'s but only at the beginning of the string as there will be some <br>'s inside the content which should stay.

 

Any idea how to solve this?

Link to comment
Share on other sites

I just quickly tested this, but it seems to work. Takes off any leading and trailing <br>, <br />, <br/>, <br >. etc. and leaves the rest of the string alone.

 

$string = "<br /><br /><br  /><br ><br/>string of<br><br /> words <br /><br>";
echo trim($string, '<br />');
// RETURNS string of<br><br /> words

 

 

 

Link to comment
Share on other sites

trim($string, '<br />');

 

Just to make it clear, this code will remove more than just <br> tags from the start of a string. Given breakfast the result would be eakfast, given <b>robber</b> would result in obbe.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.