简体   繁体   中英

how to change “<br /></p>” to “</p>” by PHP code?

How to remove all br tags before end of paragraph? Actually I want to change

<br /></p>

to

 </p>

I use this code

$content = preg_replace("/<br \/>(?!.*<br \/>)/","",$content);

but it removes all br tags!

The following regex:

/<br\s*\/{0,1}\s*>\s*<\/p>/i

will match:

<br /></p>
<br / > </p>
<br 
 /></p>
<br> 

</p>
<br ></p>
<br></p>
<br >
</p>

case-insensitively.

If you need a step-by-step explanation of the regex then plug it into the "Expression" field at https://regexr.com/

Well if you just want to replace the string < br /></p> to </p>

Just use str_replace

$content = str_replace(array('<br /></p>','<br/></p>'), '</p>', $content);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM