Reputation: 11382
Why does php
's shell_exec
command add an unwanted line break (\r\n) to the output and how can I prevent that?
test.php:
<?php
var_dump(shell_exec('echo "test"'));
running php test.php
results in:
string(5) "test
"
Upvotes: 3
Views: 4065
Reputation: 37975
You can pass -n
as argument to your echo
command, this will prevent echo
from outputting a trailing newline.
From the manual:
-n do not output the trailing newline
Upvotes: 2