Generates an obfuscated version of a string. Text passed through this method is less likely to be read by web crawlers and robots, which can be helpful for spam prevention, but can prevent legitimate robots from reading your content.
echo HTML::obfuscate($text);
string Core_HTML::obfuscate( string $string )
参数列表
参数 类型 描述 默认值 $string
string
String to obfuscate
string
public static function obfuscate($string)
{
$safe = '';
foreach (str_split($string) as $letter)
{
switch (rand(1, 3))
{
// HTML entity code
case 1 :
$safe .= '&#' . ord($letter) . ';';
break;
// Hex character code
case 2 :
$safe .= '&#x' . dechex(ord($letter)) . ';';
break;
// Raw (no) encoding
case 3 :
$safe .= $letter;
}
}
return $safe;
}