raku Posted December 25, 2007 Share Posted December 25, 2007 Hi, I am trying to remove all links and everything in between them from a string. preg_replace("/<a\b[^>]*>(.*?)<\/a>/i", "", $string); only works if the <a> tag and the other text are right next to each other or separated by spaces, it doesn't work for line breaks. For example.. it successfully removes everything in this string (sorry the closing tags of the hyperlinks was translated by the forum into [/url]): <a href="test"> test test test</a> But does nothing for this string: <a href="test"> test test test test </a> My guess is that I need something for line breaks in the preg_replace, but I'm not sure what it is. Any idea how I can fix this? Thanks! edit: I tried adding "/n" to the regexp, but then everything got removed, even stuff before the <a> tag. Link to comment https://forums.phpfreaks.com/topic/83097-solved-remove-all-links-and-everything-in-between/ Share on other sites More sharing options...
raku Posted December 25, 2007 Author Share Posted December 25, 2007 adding \r\n doesn't work either Link to comment https://forums.phpfreaks.com/topic/83097-solved-remove-all-links-and-everything-in-between/#findComment-422743 Share on other sites More sharing options...
raku Posted December 25, 2007 Author Share Posted December 25, 2007 adding "/(\r\n|\r|\n)+/" worked Link to comment https://forums.phpfreaks.com/topic/83097-solved-remove-all-links-and-everything-in-between/#findComment-422768 Share on other sites More sharing options...
effigy Posted December 25, 2007 Share Posted December 25, 2007 Use the /s modifier to include new lines in .. Link to comment https://forums.phpfreaks.com/topic/83097-solved-remove-all-links-and-everything-in-between/#findComment-422956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.