Greytree

TamWiki

For a mouse who is a packrat

Technology » Remember To Chop Returns From Commands
Trimming excess white space from command returns

Summary:this is what goes at the top of the site

(redirected from Main.RememberToChopReturnsFromCommands)

Next: Testing >>

<< Prev: Management

Up: ^Programming^

When calling commands from PHP, using either the backtick operators or shell_exec(), often times the command returns with trailing white space that you don't want. The way to eliminate this is with the trim() or rtrim() functions:

In PHP
  1. $result = rtrim(`date "+%Y-%m-%d"`);
In Perl
  1. my $result = `date "+%Y-%m-%d"`;
  2. chomp($result);
In Ruby
  1. result = `date "+%Y-%m-%d"`.chomp


Tags: Categories: Articles

Recent Changes | Printable View | Page History | Edit Page
Page last modified on April 17, 2012, at 08:59 PM by ImportText?