drisate Posted January 23, 2012 Share Posted January 23, 2012 Hey guys i have a small code that replaces all the links in a string. It works great ... but i just noticed it also replaces the mailto witch causes problems My regex looks like this #href=['|\"](.+?)['|\"]# I need to modify it so mailto links are not replaced href="mailto:hello@domail.com" While every othe forms of link remains replaced. function matche($matches){ $url = str_replace('http://', '', $matches[1]); $url = str_replace('www.', '', $url); return 'href="$domain?email=XX_EMAIL&nid=XX_ID&redirect='.base64_encode($url).'"'; } $messages = preg_replace_callback("#href=['|\"](.+?)['|\"]#","matche",html_decode($messages)); Quote Link to comment https://forums.phpfreaks.com/topic/255620-link-replace-but-not-mailto/ Share on other sites More sharing options...
ragax Posted January 23, 2012 Share Posted January 23, 2012 First thing that comes to mind: Insert a negative lookahead in your working regex. #href=(?!"mailto)['|\"](.+?)['|\"]# Quote Link to comment https://forums.phpfreaks.com/topic/255620-link-replace-but-not-mailto/#findComment-1310430 Share on other sites More sharing options...
drisate Posted January 23, 2012 Author Share Posted January 23, 2012 Yeah worked great thx playful :-) Quote Link to comment https://forums.phpfreaks.com/topic/255620-link-replace-but-not-mailto/#findComment-1310431 Share on other sites More sharing options...
ragax Posted January 23, 2012 Share Posted January 23, 2012 Good news, drisate, glad to hear it. :-) Quote Link to comment https://forums.phpfreaks.com/topic/255620-link-replace-but-not-mailto/#findComment-1310432 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.