/**
* Returns a rot13 encrypted string as well as a JavaScript decoder function.
* @param string $inputString The string to encrypt
* @return string An encoded javascript function
*/
function js_rot13_encode($inputString) {
$rotated = str_replace('"','\"',str_rot13($inputString));
return <<<EOF
<script type="text/javascript">
/*<![CDATA[*/
document.write("$rotated".replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}));
/*]]>*/
</script>
EOF;
// N.B Make sure there are no whitespace or extra characters following the semicolon above!
}
// ========
// = Demo =
// ========
echo js_rot13_encode('<a href="mailto:user@host.com">user@host.com</a>');
echo js_rot13_encode('user@host.com');