preg_match_all I want to match the regular expression as intended

Asked 1 years ago, Updated 1 years ago, 52 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?

$content

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

Current Code

if(preg_match_all('|<a href="#title.*?">(.*?)</a>br>|mis', $content, $matches, PREG_SET_ORDER)){
    if(!empty($matches)){
        $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

</a>(\r\n|\r|\n)<br>

What if?


2022-09-30 14:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.