Skip to content

Instantly share code, notes, and snippets.

@refo
Last active October 8, 2015 22:20
Show Gist options
  • Save refo/2552f82885a2af90bbc2 to your computer and use it in GitHub Desktop.
Save refo/2552f82885a2af90bbc2 to your computer and use it in GitHub Desktop.
Obfuscate string to prevent scraping / harvesting (e.g. e-mail addresses)
<?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