preg_match_all I want to match the regular expression as intended

Asked 5 months ago, Updated 5 months ago, 12 views

I would like to remove all &a> tags and all &br> tags after which the href starts with #title as shown below.
preg_match_all is not working well with the current code.
How should I change it?


<a href="#title1">stack</a>
<a href="#title2">overflow</a>

Current Code

if(preg_match_all('|<a href="#title.*?">(.*?)</a>br>|mis', $content, $matches, PREG_SET_ORDER)){
        $content=preg_replace('|<a href="#title.*?">(.*?)</a>br>|mis',',',$content);

php regular-expression

2022-09-30 14:25

1 Answers

I suspect that there is a new line code (\r\n or \r or \n or \n) between <a> and , so I'll put the relevant part


What if?

2022-09-30 14:25

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.