Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Add null character to string

I'm trying to append a number of NULL characters '\0' to a string in PHP.

$s = 'hello';
while(strlen($s) < 32) $s .= '\0';

However, PHP adds 2 characters (\ and 0), instead of escaping the character and adding NULL. Does anyone know to add a NULL character to a string?

like image 495
goocreations Avatar asked Dec 11 '22 22:12

goocreations


1 Answers

I don't know if \0 is correct in your case, but you should use ":

$s = 'hello';
while(strlen($s) < 32) $s .= "\0";
like image 135
t.h3ads Avatar answered Dec 25 '22 15:12

t.h3ads