How do I find email patterns in a query string in a text and urlescape them?

From: Date: Wed, 22 Jan 2003 01:36:02 +0000
Subject: How do I find email patterns in a query string in a text and urlescape them?
Groups: php.general 
Request: Send a blank email to php-general+get-132540@lists.php.net to get a copy of this message
If I have a text of string like this: $stuff = "Hi my name is Phil, my email is xx@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@yy.com to <a href=mailto:xx@yy.com>xx@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('/[\n\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

« previous php.general (#132540) next »