2010-08-20 95 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。控制檯是不同的。