org\parser\driver\Markdown::encodeEmailAddress PHP Метод

encodeEmailAddress() защищенный Метод

protected encodeEmailAddress ( $addr )
    protected function encodeEmailAddress($addr)
    {
        #
        #    Input: an email address, e.g. "[email protected]"
        #
        #    Output: the email address as a mailto link, with each character
        #        of the address encoded as either a decimal or hex entity, in
        #        the hopes of foiling most address harvesting spam bots. E.g.:
        #
        #      <p><a href="&#109;&#x61;&#105;&#x6c;&#116;&#x6f;&#58;&#x66;o&#111;
        #        &#x40;&#101;&#x78;&#97;&#x6d;&#112;&#x6c;&#101;&#46;&#x63;&#111;
        #        &#x6d;">&#x66;o&#111;&#x40;&#101;&#x78;&#97;&#x6d;&#112;&#x6c;
        #        &#101;&#46;&#x63;&#111;&#x6d;</a></p>
        #
        #    Based by a filter by Matthew Wickline, posted to BBEdit-Talk.
        #   With some optimizations by Milian Wolff.
        #
        $addr = "mailto:" . $addr;
        $chars = preg_split('/(?<!^)(?!$)/', $addr);
        $seed = (int) abs(crc32($addr) / strlen($addr));
        # Deterministic seed.
        foreach ($chars as $key => $char) {
            $ord = ord($char);
            # Ignore non-ascii chars.
            if ($ord < 128) {
                $r = $seed * (1 + $key) % 100;
                # Pseudo-random function.
                # roughly 10% raw, 45% hex, 45% dec
                # '@' *must* be encoded. I insist.
                if ($r > 90 && '@' != $char) {
                    /* do nothing */
                } elseif ($r < 45) {
                    $chars[$key] = '&#x' . dechex($ord) . ';';
                } else {
                    $chars[$key] = '&#' . $ord . ';';
                }
            }
        }
        $addr = implode('', $chars);
        $text = implode('', array_slice($chars, 7));
        # text without `mailto:`
        $addr = "<a href=\"{$addr}\">{$text}</a>";
        return $addr;
    }