PHP - Adds a null character to a string

advertisements

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?


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

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