Skip to content

Instantly share code, notes, and snippets.

@jeffreyroberts
Created November 3, 2013 06:31
Show Gist options
  • Save jeffreyroberts/7287411 to your computer and use it in GitHub Desktop.
Save jeffreyroberts/7287411 to your computer and use it in GitHub Desktop.
PHP String to Hex, Javascript Unescape
<?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