/**
* Encodes an email address in multiple ways.
* @param $str String The email address to encode.
* @version $url_encode bool Should we use url encoding? Do not use this for displaying, only for mailto: links.
*/
public function encode_email_address($str, $url_encode = true)
{
if (empty($str))
return;
$strlength = strlen($str);
$ret = '';
for($index = 0; $index < $strlength; $index++)
{
$type = rand(1, $url_encode ? 4 : 3);
$char = $str[$index];
switch($type)
{
case 1: $ret .= '&#' . ord($char) . ';'; break;
case 2: $ret .= '&#x' . dechex(ord($char)) . ';'; break;
case 3: $ret .= $char; break;
case 4: $ret .= '%' . bin2hex($char); break;
}
}
return $ret;
}
* Encodes an email address in multiple ways.
* @param $str String The email address to encode.
* @version $url_encode bool Should we use url encoding? Do not use this for displaying, only for mailto: links.
*/
public function encode_email_address($str, $url_encode = true)
{
if (empty($str))
return;
$strlength = strlen($str);
$ret = '';
for($index = 0; $index < $strlength; $index++)
{
$type = rand(1, $url_encode ? 4 : 3);
$char = $str[$index];
switch($type)
{
case 1: $ret .= '&#' . ord($char) . ';'; break;
case 2: $ret .= '&#x' . dechex(ord($char)) . ';'; break;
case 3: $ret .= $char; break;
case 4: $ret .= '%' . bin2hex($char); break;
}
}
return $ret;
}