Re: how to seek and convert an email address to mailto link
| From: | Miguel Cruz | Date: | Wed, 20 Mar 2002 00:25:41 +0000 |
| Subject: | Re: how to seek and convert an email address to mailto link | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-89243@lists.php.net to get a copy of this message | ||
On Tue, 19 Mar 2002, Pekka Saarinen wrote:
> I need to search text for @ and replace the mail address around it (i.e.
> text between previous and following spaces) so that if I have text
>
> Foobar foobar foo@foo.com foobar foobar.
>
> It'll convert it to
>
> Foobar foobar <a
> href="mailto:foo@foo.com">foo@foo.com</a> foobar
> foobar.
(warning: untested)
$newstr = preg_replace('/\b(\S+@\S+)\b/',
'<a href="mailto:\1">\1</a>',
$oldstr);
Take the time to learn Perl-style regular expressions. You can practically
write Photoshop with them.
miguel