freshwebs Posted November 7, 2006 Share Posted November 7, 2006 So I'm an idiot with regular expressions, I can't ever seem to figure them out. Could someone help me make a regular expression that will find all the anchors in a block of text and add a target="_blank" attribute to them? It would be [i]greatly[/i] appreciated.Thanks!!! Link to comment https://forums.phpfreaks.com/topic/26468-regex-to-add-target-attribute-to-html-links/ Share on other sites More sharing options...
Nicklas Posted November 8, 2006 Share Posted November 8, 2006 [code]$string = preg_replace('/(<a href[^<>]+)>/is', '\\1 target="_blank">', $string);[/code] Link to comment https://forums.phpfreaks.com/topic/26468-regex-to-add-target-attribute-to-html-links/#findComment-121347 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.