For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > March 2008 > Backtick call appends extra space









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

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?

Heiko Richler

2008-03-31, 8:13 pm

Martin wrote:
> There is an extra space after the "2008". [...] what can I
> do about it?


use trim(...)

--
http://portal.richler.de/ Namensportal zu Richler
http://www.richler.de/ Heiko Richler: Computer - Know How!
http://www.richler.info/ private Homepage
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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com