I know that:
preg_replace('<br\s*\/?>', '', $string);
will remove all br tags from $string…
How can we remove all <br><br/><br /> tags only if they are in the very beginning of $string? ($string in my case is html code with various tags…)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Just add an appropriate anchor (
^):This will match multiple
<br>s at the beginning of the string.(?:…)is a non-capturing group since we only use the parentheses here to group the expression, not capture it. The modifier isn’t strictly necessary –(…)would work just as well, but the regular expression engine would have to do more work because it then needs to remember the position and length of each captured hit.