Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php obfuscate email

function getObfuscatedEmailLink($email, $params = array())
{
    if (!is_array($params)) {
        $params = array();
    }

    // Tell search engines to ignore obfuscated uri
    if (!isset($params['rel'])) {
        $params['rel'] = 'nofollow';
    }

    $neverEncode = array('.', '@', '+'); // Don't encode those as not fully supported by IE & Chrome

    $urlEncodedEmail = '';
    for ($i = 0; $i < strlen($email); $i++) {
        // Encode 25% of characters
        if (!in_array($email[$i], $neverEncode) && mt_rand(1, 100) < 25) {
            $charCode = ord($email[$i]);
            $urlEncodedEmail .= '%';
            $urlEncodedEmail .= dechex(($charCode >> 4) & 0xF);
            $urlEncodedEmail .= dechex($charCode & 0xF);
        } else {
            $urlEncodedEmail .= $email[$i];
        }
    }

    $obfuscatedEmail = getObfuscatedEmailAddress($email);
    $obfuscatedEmailUrl = getObfuscatedEmailAddress('mailto:' . $urlEncodedEmail);

    $link = '<a href="' . $obfuscatedEmailUrl . '"';
    foreach ($params as $param => $value) {
        $link .= ' ' . $param . '="' . htmlspecialchars($value). '"';
    }
    $link .= '>' . $obfuscatedEmail . '</a>';

    return $link;
}
Comment

php obfuscate email

echo getObfuscatedEmailLink('firstname.last-name@example.com');
-->
<a href="mailto:%66i%72stna%6de.%6c%61st-name@example.com" rel="nofollow">firstname.last-name@example.com</a>
Comment

PREVIOUS NEXT
Code Example
Php :: Error : Call to undefined method IlluminateNotificationsChannelsMailChannel::assertSentTo() 
Php :: octobercms mail view 
Php :: php call non static method from static method 
Php :: php fpdf in phpmailer 
Php :: Pure Intersection Types - PHP 8.1 
Php :: READIMAGE FUNCTION PHP 
Php :: php function return multiple values 
Php :: php const scope 
Php :: php mail() 
Php :: how to re assign value of associative array after assign in php 
Php :: hot to use functions in heredoc 
Php :: How to make a simple mail system in Laravel without view or notification 
Php :: php check if item in array 
Php :: laravel collection nth method 
Php :: laravel collection find 
Php :: coinbase commerce laravel 
Php :: wpquery search taxonomy 
Php :: wordpress theme basics including CSS and js 
Php :: havingraw in laravel 
Php :: php artisan websockets serve 
Php :: Using $this when not in object context 
Php :: png to pdf 
Php :: how to migrate new column without empty the table in laravel 
Php :: Laravel whereHas with count 
Php :: which is file attributes in php 
Php :: wordpress get all published post 
Php :: enable phpmailer cpanel 
Php :: route list laravel 8 
Php :: loop through objects in php 
Php :: relationship in laravel 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =