| Author |
Backtick call appends extra space
|
|
| Martin 2008-03-31, 8:11 pm |
| Look at the following code:
<?php
$year = `date +
%Y`;
echo "(".$year.")";
?>
The output is
(2008 )
There is an extra space after the "2008". Why is that, and what can I
do about it?
| |
|
|
| Jeremy 2008-03-31, 8:15 pm |
| Martin wrote:
> Look at the following code:
> <?php
> $year = `date +
> %Y`;
> echo "(".$year.")";
> ?>
>
> The output is
> (2008 )
>
> There is an extra space after the "2008". Why is that, and what can I
> do about it?
>
It's not a space, it's a linefeed (look at the source generated; the
linefeed is converted to a space for presentation because of HTML
whitespace rules). This will happen with pretty much any command line
utility; they all must print a linefeed after their output to get your
prompt on the following line.
And like Heiko Richler said - trim() the output and you shouldn't have
any problems.
Jeremy
|
|
|
|