2010-08-20 97 views
0

我有我通过命令行运行像打印更好的格式化

php file.php 

,并在该文件中我有一个像

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

我以为BR将打印语句PHP脚本Formant it 1 below other,but when I run the script,I get this format that is 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 

,因此格式化在控制台中很难读取。有没有办法调整自己的打印有这样

Saved the url: http://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 

回答

5

使用换行符而不是br。

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

如果您希望与HTML输出工作,以及可以查看哪个SAPI你与运行:

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

现在只需更换'\ N'为'PHP_EOL'和我给予好评 – Gordon 2010-08-20 17:22:07

+1

呵呵。满意? :) – 2010-08-20 17:22:53

+0

如果您不介意输出中的BR,您可以随时执行这两种操作 - “
\ n' – Jenni 2010-08-20 17:38:18

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

输出您是否尝试过\ n \ r或\ n吗?
适用于html。控制台是不同的。