Re: Backtick call appends extra space

Re: Backtick call appends extra space

am 31.03.2008 23:13:08 von Jeremy

Martin wrote:
> Look at the following code:
> > $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