PHP- trim() function not working

php, trim

Solution

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

Problem

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 `'.'`.

Original source