1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?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> <script type="text/javascript"> document.write( unescape( '%54%68%69%73%20%69%73%20%73%6f%6d%65%20%73%61%6d%70%6c%65%20%74%65%78%74%2e' ) ); </script> |
输出
This is some sample text.