I have problem when used function trim()
with this code
$handle = @fopen("55.txt", "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
$d = explode(" ", $buffer);
foreach($d as $val) {
echo '<br>'.trim($val,'.'); //why not work
}
}
if (!feof($handle)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}
The trim()
doesn't trim '.'
.
Additional to the lines themselves, the fgets()
function returns the line breaks from the file, which are after the dots in the string, thus preventing the dots from being trimmed, because they are not actually the last character.
Try to trim the dots and possible line breaks at the same time:
echo '<br>'.trim($val, ".\r\n");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With