Re: Re: Makeing automatic tags for email and www.

From: Date: Wed, 15 Oct 2003 14:32:19 +0000
Subject: Re: Re: Makeing automatic tags for email and www.
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-166213@lists.php.net to get a copy of this message
On Wed, Oct 15, 2003 at 04:16:14AM -0500, Gabriel Peugnet wrote: : : Thanks Eugene. : : I'm afraid I didn't explain my self as I should. : : What I want is this to be automaticaly generated in a text. : For example, in: : : "Some text some text some text some text my@mail.com some text some text : some text and www.mywebpage.com some text some text some text : another@mail.com some text some text some text ." You're so close... <?php function emaillink($email) { $email = htmlentities($email); return '<a href=\'mailto:' . $email . '\'>' . $email . '</a>'; } function emaillink_callback($matches) { return emaillink($matches[0]); } $word = "Some text some text some text some text my@mail.com some text some text some text and www.mywebpage.com some text some text some text another@mail.com some text some text some text ." echo preg_replace_callback('|(\S+@\S+)|', 'emaillink_callback', $word) . "\n"; ?> Of course, the equivalent code for web sites is left as an exercise. But you get the idea. :-) The tough part is figuring out the regular expression pattern. : "Gabriel Peugnet" asked: : > : > I want to convert : > my@email.com : > into : > (a href='mailto:my@email.com') my@email.com (/a)

« previous php.general (#166213) next »