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?

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

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.