note 65119 deleted from function.file by bjori
| From: | bjori@php.net | Date: | Mon, 24 Apr 2006 19:55:53 +0000 |
| Subject: | note 65119 deleted from function.file by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109605@lists.php.net to get a copy of this message | ||
Note Submitter: Raja Govindan
----
I was trying to read an output from a shell script execution and display on a webpage. File reading
and displaying on STDOUT (monitor) is all fine , but when display it on a web page, the end new line
character diplays an additional blank lines.
Below all failed to remove the blank line character...
----------------------------------------------------
#echo "<b><font color=blue><pre>" .htmlspecialchars($line) .
"</pre></br
>";
#echo "<b><font color=blue><pre>" .str_replace("\n",
" ", $line) . "</p
re></br>";
#echo "<b><font color=blue><pre>". ltrim($line) .
"</pre></br>"; // get
rid of any leading spaces
#echo "<b><font color=blue><pre>". rtrim($line) .
"</pre></br>"; // ge
t rid of any newline characters
#echo "<b><font color=blue><pre>". substr($line, 0, 70) .
"</pre></br>"
; // get rid of any newline characters
echo "<b><font color=blue>". $line . "</br>"; // get
rid of any newline characters
output was consistent on IE 6.0
----------------------------------
> total 14550
> drwxr-xr-x 2 staff abc 512 Aug 26 2005 .
> drwxr-xr-x 19 staff abc 512 Feb 16 14:48 ..
> -rw-r--r-- 1 staff abc 7435385 Aug 18 file_out
> -rw-r--r-- 1 oracle dba 50 Aug 18 2005 ut_2
--------------------------------------------------
Correct script :
Below script is used to get rid of the additional new line character.
--
$contents = file ('ftp_files.out');
foreach ($contents as $value)
{
# IF new line character is not found then then print the line
#
echo ($value{0}!="\n")? "<pre>". $value. "<br>" :
"</pre>";
}
output is :
-----------------------------------------------------------
> total 14550
> drwxr-xr-x 2 staff abc 512 Aug 26 2005 .
> drwxr-xr-x 19 staff abc 512 Feb 16 14:48 ..
> -rw-r--r-- 1 staff abc 7435385 Aug 18 file_out
> -rw-r--r-- 1 oracle dba 50 Aug 18 2005 ut_2
-----------------------------------------------------------