PHP: \r 字符被忽略

PHP: \r character being ignored

我有一个字符串 $s="one\rtwo\rthree\rfour\rfive",当我这样做时 print $s 我希望看到 five 只是因为换行会重置该行。

相反,我似乎看到了 one two three four five

怎么回事?

如果你想在控制台中重写一行window(就像你正在尝试做的那样)你可以这样做:

#!/c/PHP/php-7.0/php.exe <?php for($i = 0; $i < 100; $i++){ fwrite(STDOUT, "\r$i%"); }

或者,如果您只想用回车符分隔字符串的最后一部分 returns,您可以这样做:

$endVal = end(explode("\r", $s)); print($endVal);