$var1 = "a<b>
b<br>
c
";
$var2 = "a<b>
b<br>
c<br>
";
How can I detect and delete the <br> after the c in $var2?
Thanks.
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.
What about a regex solution
it is also working with optional newlines and whitespace at the end of the string.
$anchors the regex to the end of the string.\sis a whitespace character (this includes newlines)*means 0 or moreThat means the regex matches a
<br>followed by optional whitespace at the end of the string andpreg_replacereplaces it with an empty string.