Forums

  • # 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 = 'https://cdn.css-tricks.com/([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

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

You must be logged in to reply to this topic.

icon-anchoricon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag