(redirected from Main.RememberToChopReturnsFromCommands)
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
- $result = rtrim(`date "+%Y-%m-%d"`);
In Perl
- my $result = `date "+%Y-%m-%d"`;
- chomp($result);
In Ruby
- 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?