Get a free trial // Grow your CSS skills // Land your dream job

Php/Javascript to Find All Email Addresses, and Make Links From Them.

  • # December 8, 2011 at 4:28 pm

    Basically I have this in the html:

    And I want to have php make that into this:

    If necessary, I could use javascript, but I’d like to keep this to the server-side.

    # December 12, 2011 at 3:17 pm

    Something along the lines of this? :

    < ?php
    $content ='

    $addr_pattern = '/([A-Z0-9._%+-]+)@([A-Z0-9.-]+).([A-Z]{2,4})(((.+?)))?/i';
    preg_match_all($addr_pattern, $content, $addresses);
    $the_addrs = $addresses[0];
    for ($a = 0; $a < count($the_addrs); $a++) {
    $repaddr[$a] = preg_replace($addr_pattern, '$1@$2.$3', $the_addrs[$a]);
    $cc = str_replace($the_addrs, $repaddr, $content);

    echo $cc;

    based on :

    # December 12, 2011 at 7:00 pm

    There is a wordpress plugin that does this really well. I would suggest taking a look at the source code and seeing what you can get from it.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed