Last active
October 8, 2015 22:20
-
-
Save refo/2552f82885a2af90bbc2 to your computer and use it in GitHub Desktop.
Obfuscate string to prevent scraping / harvesting (e.g. e-mail addresses)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ------------------------------------------------- | |
// Kohana 3.0'dan alıntı | |
// HTML::obfuscate | |
// ------------------------------------------------- | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment