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:

    example@example.com

    And I want to have php make that into this:

    example@example.com

    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 ='
    example@example.comexample@example.co.uk
    ';

    $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 : http://stackoverflow.com/questions/5068676/regex-to-detect-plain-email-and-mailto-link-emails

    # 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. http://www.semiologic.com/software/autolink-uri/

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

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".