如何让PHP CLI在OS X上使用换行符?

时间:2014-04-28 14:36:37

标签: php macos terminal newline command-line-interface

我在Mac OS X终端上遇到PHP的交互式shell问题。也就是说,它在每个命令后都没有换行符:

php > echo "Hello Stack Overflow!";
Hello echo "As you can see, there was no newline.";                            As you can see, there was no newline.php > echo "As you can see, there was no newlineecho "It even deletes my sentences if I go up and then down in history."; 
It even deletes my sentences if I go up and then down in history.php > 

正如你所知,我甚至无法在我的历史中上下,因为它破坏了缓冲区并使其变得如此我不知道我在输入什么。有谁知道如何解决这个问题?

我的PHP版本:

$ php -v
PHP 5.4.24 (cli) (built: Jan 19 2014 21:32:15) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

2 个答案:

答案 0 :(得分:2)

$ php > echo "Hello" . PHP_EOL . "World!";

正确的行结束'这个平台的象征。自PHP 4.3.10和PHP 5.0.2起可用

答案 1 :(得分:0)

如果要在CLI中使用新行,请使用显式返回运输:

$ php > echo "Hello\r\nWorld!";

应输出:

$ Hello
World!