Created
November 3, 2013 06:31
-
-
Save jeffreyroberts/7287411 to your computer and use it in GitHub Desktop.
PHP String to Hex, Javascript Unescape
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 | |
// Javascript/HTML hex encode | |
function encode($input) | |
{ | |
$temp = ''; | |
$length = strlen($input); | |
for($i = 0; $i < $length; $i++) | |
$temp .= '%' . bin2hex($input[$i]); | |
return $temp; | |
} | |
$str = encode('This is some sample text.'); | |
?> | |
<script language="javascript"> | |
document.write( unescape( '<?php echo $str; ?>' ) ); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment