Backtick call appends extra space

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin

    #1

    Backtick call appends extra space

    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

    #2
    Re: Backtick call appends extra space

    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

    Comment

    • Jeremy

      #3
      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

      Comment

      Working...