UTF-8 PHP obfuscation with Javascript
php
,
html
,
javascript
,
utf8
Jose Luis Canciani (josecanciani at Twitter)
My goal was to write text in a way that bots cannot read it when shown in a HTML page. Javascript should do.
First thing I've tried was to find a javascript-like decodeURI function in PHP which would have made this work very easy, but the only one I could find (www.captain.at), was not working properly with UTF-8 strings. So I decide to write a very simple one my own.
It's simple the document.write function writing parts of the text. For UTF-8 to work I had to find a function to replace "substr" becouse it does not play well with UTF-8 strings. From the php.net user manual I've found this one:
function utf8_substr($str,$from,$len){
# utf8 substr
# www.yeap.lv
return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.
'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s',
'$1',$str);
}
After I have that function, the other one was simple:
function js_obfuscate($text,$step=4) {
echo ''.chr(10);
}
$step defines how many characters the function will print in each document.write call.
Hope you like it! If you find something better, you are free to leave a comment! A encodeURI/decodeURI that works with UTF-8 would be great.

Aún no hay comentarios. Se el primero en hacerlo!