regex - php regular expression to replace HREF attribute -


how use php preg_replace , regular expression remove hyperlink contain <a href="#. here write, doesn't work

$newlink = preg_replace('/^<a href="#(.*)" (?:.*?)>(.*)<\/a>/is', '', $link); 

i want replace these links aa anchor mark

<a href="#part1">go part1</a> <a href="#part2">go part2</a> <a href="#part3">go part3</a> 

to empty value.

let me start saying using regular expressions parsing/modifying html documents can wrong approach. i'd encourage check out dom document if you're doing other modifications.

with said, making expression non-greedy (.*?) work.

$newlink = preg_replace('/^<a href="#(.*?)"[^>]+>(.*?)<\/a>/', '', $link); 

note: assumes href first attribute in anchor tags. may poor assumption.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -