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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
raku Posted December 25, 2007 Author Share Posted December 25, 2007 adding "/(\r\n|\r|\n)+/" worked Quote Link to comment 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 .. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.