PHP - 将空字符添加到字符串

goo*_*ons 2 php string null padding

我正在尝试将多个NULL字符'\ 0'附加到PHP中的字符串中.

$s = 'hello';
while(strlen($s) < 32) $s .= '\0';
Run Code Online (Sandbox Code Playgroud)

但是,PHP添加了2个字符(\和0),而不是转义字符并添加NULL.有没有人知道在字符串中添加NULL字符?

t.h*_*ads 7

我不知道\0你的情况是否正确,但你应该使用":

$s = 'hello';
while(strlen($s) < 32) $s .= "\0";
Run Code Online (Sandbox Code Playgroud)

  • 以下是一些进一步的解释:http://stackoverflow.com/questions/1318028/php-different-quotes (2认同)