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);
?>