michaellunsford Posted January 10, 2007 Share Posted January 10, 2007 I created a function that turns an email address to an html entity using [color=blue]ord()[/color]. Instead of [color=blue]ord()[/color]ing each letter individualy, I'm wondering if there would be a way to regexp the second parameter of preg_replace?[code=php:0]preg_replace("/[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/",$what_goes_here,$subject);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33639-obfuscating-email-addresses-using-preg_replace/ Share on other sites More sharing options...
Eclesiastes Posted January 23, 2007 Share Posted January 23, 2007 http://www.php.net/preg-replace-callback Quote Link to comment https://forums.phpfreaks.com/topic/33639-obfuscating-email-addresses-using-preg_replace/#findComment-167116 Share on other sites More sharing options...
michaellunsford Posted February 13, 2007 Author Share Posted February 13, 2007 Okay[list][*]the output is correct.[*]I'm no longer stepping through the entire string, one character at a time.[*]The code went from 34 lines down to 8 lines.[/list]But can it be reduced further?[code]<?php$var="<a href=\"mailto:[email protected]\">[email protected]</a> is our primary <a href=\"mailto:[email protected]\">contact</a>";$newvar=preg_replace_callback("/[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i",create_function('$matches','return obfuscate_me($matches[0]);'),$var);echo $newvar;function obfuscate_me($my_array) { return preg_replace_callback("/[A-Z0-9]/i",create_function('$matches','return "&#".ord($matches[0]).";";'),$my_array);}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33639-obfuscating-email-addresses-using-preg_replace/#findComment-183191 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.