PHP Issue with escaped hex characters -


i'm running php code , error.

php fatal error:  call undefined function \\x66\\x6f\\x6f() 

below code:

function string2binary($string) {     $binary = '';     $binarr = str_split( $string );      ( $i=0; $i < count( $binarr ); $i++ )         $binary.=strlen(decbin(ord($binarr[$i])))<8?str_pad(decbin(ord($binarr[$i])),8,0,str_pad_left):decbin(ord($binarr[$i]));      return $binary; }  function binary2string($binary) {     $string = '';     $chars  = explode( ' ' , chunk_split( $binary , 8 , ' ' ) );      ( $i = 0; $i < count( $chars ); $i++ )         if ( ! empty( $chars[$i] ) )             $string .= chr( bindec( $chars[$i] ) );      return $string; }  function foo( $bar = 'bar' ) {     echo $bar . '<br />'; }  $fn = "foo";  echo $fn . '<br />';  $fn();  $fn = "\x66\x6f\x6f";  echo $fn . '<br />';  $fn();  $fn = string2binary( "foo" );  echo $fn . '<br />';  $fn = binary2string( $fn );  echo $fn . '<br />';  $fn();  $fn = string2binary( '\x66\x6f\x6f' );  echo $fn . '<br />';  $fn = binary2string( $fn );  echo $fn . '<br />';  $fn(); 

output

foo bar foo bar 011001100110111101101111 foo bar 010111000111100000110110001101100101110001111000001101100110011001011100011110000011011001100110 \x66\x6f\x6f php fatal error:  call undefined function \\x66\\x6f\\x6f() 

i somehow need treat string hex sequences instead of flat string. error mean?

you have use stripcslashes

$fn = binary2string( $fn ); echo stripcslashes($fn) . '<br />'; 

use value call function, this:

function foo() { echo 'call'; }  $bar = '\x66\x6f\x6f'; $fooname = stripcslashes($bar);  echo $fooname . "\n"; $fooname(); 

demo: http://3v4l.org/cjbbm


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -