Re: Make all emails links

From: Date: Thu, 09 Mar 2006 05:21:03 +0000
Subject: Re: Make all emails links
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-231704@lists.php.net to get a copy of this message
I agree, your regexp are bad (jk) What you need is a regexp that matches an email address. Look for something like "regexp email" on Google (without the quotes) or something similar and you should find some regexp to validate an email address; once you have it use it with preg_replace() like Bekko did -or its EGREP equivalent. Example (using the first one I found, a bit modified): $regexp = '/[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]/Xi'; $string = preg_replace($regexp, '<a href="mailto:$1">$1</a>', $string); El Bekko wrote:
Benjamin Adams wrote:
I'm pulling data from a database; When the data is pulled emails look like example@sample.com Is there a way to just make all email address in the text that it pulls so, "bla bla bla okjsokdf exmaple@sample.com ksnow noduowe..." Make the email in the text be a mailto link automatically? Thanks -Ben
With a RegExp ;) Something like this (yes my RegExp is bad): <?php $message = preg_replace("#[*].[@].[*].\..[*]#i","<a href=\"mailto:$1\">$1</a>",$message); ?> -- Atentamente, J. Rafael Salazar Magaña Innox - Innovación Inteligente Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE http://www.innox.com.mx


« previous php.general (#231704) next »