note 62040 modified in function.rtrim by danbrown
| From: | danbrown@php.net | Date: | Sun, 14 Dec 2008 17:22:11 +0000 |
| Subject: | note 62040 modified in function.rtrim by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148152@lists.php.net to get a copy of this message | ||
True, the Perl chomp() will only trim newline characters. There is, however, the Perl chop()
function which is pretty much identical to the PHP rtrim()
---
Here's a quick way to recursively trim every element of an array, useful after the file()
function :
<?php
# Reads /etc/passwd file an trims newlines on each entry
$aFileContent = file("/etc/passwd");
foreach ($aFileContent as $sKey => $sValue) {
$aFileContent[$sKey] = rtrim($sValue);
}
print_r($aFileContent);
?>
--was--
True, the Perl chomp() will only trim newline characters. There is, however, the Perl chop()
function which is pretty much identical to the PHP rtrim()
---
Here's a quick way to recursively trim every element of an array, useful after the file()
function :
# Reads /etc/passwd file an trims newlines on each entry
$aFileContent = file("/etc/passwd");
foreach ($aFileContent as $sKey => $sValue) {
$aFileContent[$sKey] = rtrim($sValue);
}
print_r($aFileContent);
http://php.net/manual/en/function.rtrim.php