How do I find email patterns in a query string in a text and urlescape them?
Phil Powell
soazine at erols.com
Tue Jan 21 20:36:02 EST 2003
If I have a text of string like this:
$stuff = "Hi my name is Phil, my email is xx at yy.com and you can find me at http://www.xx.yy?username=xx@yy.com";
What I want to do is to "validate" all patterns resembling an email address EXCEPT those found within the query string of a URL. I would want to to urlencode(\\\\1) somehow onto the email address pattern found within the query string of the URL to ensure that it is not "validated" like any other email address (validate means to convert xx at yy.com to <a href=mailto:xx at yy.com>xx at yy.com</a>).
Can anyone figure this out for me? I tried using pattern matching and eval() but the results were completely wrong:
function VALIDATE_URL($stuff) {
$stuff = preg_replace('/[\
\\r]/', '<br>', $stuff);
$stuff = preg_replace('/\\.\\./', ' . .', $stuff);
// URL ESCAPE ALL EMAIL ADDRESSES FOUND WITHIN QUERY STRINGS TO ENSURE PROPER VALIDATION
// IF USING VALIDATE_EMAIL
$stuff = preg_replace('/([\\?&][a-zA-Z0-9]+=)([a-zA-Z0-9_\\-\\.]+@([a-zA-Z0-9_\\-]+\\.)+[a-zA-Z0-9_\\-]+)/', '\\\\1' . '<? $stuff = urlencode("\\\\2"); echo $stuff; ?>', $stuff);
$stuff = eval('?>' . $stuff);
$stuff = preg_replace('/(http[s]?:\\/\\/([a-zA-Z0-9_\\-]+\\.)+(\\/[a-zA-Z0-9_\\-\\.\\~\\^,%\\+]+)*[^<\\(\\)> ]+)/', '<a href=\\\\1 target=_new>\\\\1</a>', $stuff);
return preg_replace('/ \\. \\./', '..', $stuff);
}
Thanx
Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20030121/276a8ccf/attachment.html>
More information about the talk
mailing list