简体   繁体   中英

How do I make the PHP CLI use newlines on OS X?

I have a problem with PHP's interactive shell on the Mac OS X terminal. Namely, it doesn't have line breaks after each command:

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 > 

As you can tell, I can't even go up and down in my history, because it corrupts the buffer and makes it so I do not know what I am typing. Does anyone know how to fix this?

My PHP version:

$ 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
$ php > echo "Hello" . PHP_EOL . "World!";

The correct 'End Of Line' symbol for this platform. Available since PHP 4.3.10 and PHP 5.0.2

If you want new lines in CLI, use the explicit return carriage:

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

should output:

$ Hello
World!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM