Why does PHP print a percent sign when my script runs?

When I run a simple echo 'Hello World'; script in PHP from my terminal on my Mac, I see a percent sign ( % ) at the end of the line.

Why is this? Can I turn this off?

 ~ php -r "echo 'Hello World';" Hello World% ~ 

Screenshot

Technically, I don't do this in bash, I run Oh My Zsh if that matters.

+12
php terminal macos
source share
2 answers

This is from zsh.

Your output does not end with a line break. Bash launches PS1 immediately after exiting, zsh prints (color)% and inserts the line break itself. You can prevent this by adding line breaks.

 php -r 'echo "Hello World\n";' 

Note. I switched "and" in php '\ n' will print it as if "\ n" means line break.

+22
source share

Add this line to .zshrc:

 PROMPT_EOL_MARK='' 

This works for me.

For a detailed explanation, you can go here: https://superuser.com/a/645612

+1
source share

All Articles