I know that:
preg_replace('<br\s*\/?>', '', $string);
will remove all br tags from the string $ ...
How can we remove tags <br><br/><br />only if they are at the very beginning of the $ line? ($ string in my case there is html code with various tags ...)
<br><br/><br />
Just add the appropriate anchor ( ^):
^
preg_replace('/^(?:<br\s*\/?>\s*)+/', '', $string);
This will match several <br>at the beginning of the line.
<br>
(?:…) - , , . - (…) , , .
(?:…)
(…)
PCRE . :
$string = preg_replace('/^\s*(?:<br\s*\/?>\s*)*/i', '', $string);
, .
:
^\s*
(?:<br\s*\/?>\s*)*
BR
$string = preg_replace( '@^(<br\\b[^>]*/?>)+@i', '', $string );
Should match:
<br> <br/> <br style="clear: both;" /> etc