Rottingham Posted December 31, 2010 Share Posted December 31, 2010 Hello I have a replace_links() function that searches HTML source and harvests all the links into an array. I'm finishing eNewsletter software and have a few last bugs to work out. My regex is: if( !preg_match_all("/<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>/siU", $template_source, $matches, PREG_SET_ORDER ) ) { echo " Failed to find any matches using regex: /<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>/siU.<br>"; return; } This works beautifully! I then add some code to change the link to point to a click tracker and insert it back into the HTML. My dilemma is that if the link includes any white spaces the regex fails. IE if I did a mailto link like this: <a href="mailto:dummy@dummer.com?subject=Thanks for visiting">Mail me</a> The regex fails. If I place any character in the whitespace, like an underscore it works fine. How can I include whitespace in that regex line? I'm not very good at this stuff! Thanks for any help. Quote Link to comment Share on other sites More sharing options...
.josh Posted January 1, 2011 Share Posted January 1, 2011 There's a space in your negative character class that's preventing the regex from matching when there is a space (I put a red X where the space is): "/<a\s[^>]*href=(\"??)([^\"X>]*?)\\1[^>]*>(.*)<\/a>/siU" Quote Link to comment Share on other sites More sharing options...
Rottingham Posted January 3, 2011 Author Share Posted January 3, 2011 Thanks your awesome! 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.