When I run a simple echo 'Hello World';
script in PHP from my terminal on my Mac, I see a percent sign (%
) appear at the end of the line.
Why is this? Can I disable this?
~ php -r "echo 'Hello World';"
Hello World%
~
Technically, I'm not doing this in bash, I'm running Oh My Zsh, if that matters.
It's the modulus operator, as mentioned, which returns the remainder of a division operation. Examples: 3%5 returns 3, as 3 divided by 5 is 0 with a remainder of 3. 5 % 10 returns 5, for the same reason, 10 goes into 5 zero times with a remainder of 5.
The shell being used in the current Terminal session will change to the Zsh and the command prompt will change to a percent sign (%). You can return to the bash shell by either quitting Terminal, or at the prompt enter: bash.
The PHP print StatementThe print statement can be used with or without parentheses: print or print() .
The docs say that these print to php://output . They are both language constructs, but at a guess, the difference is that print is an expression, but echo is a statement. printf and many friends.
This is from zsh.
Your output doesn't end with a line break. Bash would start the PS1 right after your output, zsh prints a (colored) % and insert a line break itself. You can prevent it by adding a line break yourself
php -r 'echo "Hello World\n";'
Note: I switched " and ', in php '\n' would print it as is but "\n" means line break.
Add this line to .zshrc :
PROMPT_EOL_MARK=''
It's work for me.
For detail explanation you can go here: https://superuser.com/a/645612
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With