Re: Backtick call appends extra space



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
.



Relevant Pages

  • Re: trimming extra spaces from large DB file
    ... MySQL has a trim function so I think the easiest way would be to load the ... > this list was put together, apparently there was extra space formatting ... > create such script. ...
    (alt.php)
  • Re: trimming extra spaces from large DB file
    ... MySQL has a trim function so I think the easiest way would be to load the ... > this list was put together, apparently there was extra space formatting ... > create such script. ...
    (comp.lang.php)
  • Re: Wake up, 97 Query in 2000/03
    ... I can't say I every needed to do the trim. ... wrapping a field name like: ... have been just one extra space or something!). ... and more important allow ms-access to using indexing. ...
    (microsoft.public.access.conversion)
  • trimming extra spaces from large DB file
    ... apparently there was extra space formatting ... INSERT INTO `table_one` VALUES ('Jane Doe', ... I was thinking some kind of script could be put together to trim the ...
    (comp.lang.php)
  • trimming extra spaces from large DB file
    ... apparently there was extra space formatting ... INSERT INTO `table_one` VALUES ('Jane Doe', ... I was thinking some kind of script could be put together to trim the ...
    (alt.php)