开发者

Printing better formating in command line

开发者 https://www.devze.com 2023-01-12 05:38 出处:网络
I have a php script that i run via command line like php file.php and in that file i have a print statement like

I have a php script that i run via command line like

php file.php

and in that file i have a print statement like

print "<br>Saved the url: {$url} to :{$destination}";

I assumed the br would formant it 1 below the other but when i run the script i get this format which is really hard to read

<br>Saved the url: http://example.com/a.mp3 to :/usr/recordings/3e/1555141317-2349577.mp3<br>Saved the url: http://example.com/b.mp3 to :/usr/recordings

so the formatting is really hard to read in the console. Is there a way to restructure my print to have the output like this

Saved the url: ht开发者_开发百科tp://example.com/a.mp3 to :/usr/recordings/3e/1555141317-dadfdasffa.mp3
Saved the url: http://example.com/b.mp3 to :/usr/recordings/3c/1555141317-fddfd.mp3
Saved the url: http://example.com/c.mp3 to :/usr/recordings/3f/1555141317-ffdfd.mp3


Use a newline instead of br.

print "\nSaved the url: {$url} to :{$destination}";

If you want that to work with html output as well you can check which sapi you're running with:

echo PHP_SAPI == 'cli' ? PHP_EOL : '<br>', "Saved the url: {$url} to :{$destination}";


print "Saved the url: {$url} to :{$destination}\n";


Have you tried \n\r or \n ?
is for html. Console is different.

0

精彩评论

暂无评论...
验证码 换一张
取 消