In my laravel app, I am trying to trim a result that I get from database. The trim() is not removing the last space in the string.
The code is this
$institutes = Institute::all();
foreach ($institutes as $institute) {
$str = $institute->name;
$str = trim($str); //doesn't remove the trailing space
$len = strlen($str);
}
Now, first of all, the length of $str
is 1 more than what it should be. It should be 20
but it somehow shows 21
. Another thing, the last character is a space
according to my input.
When I try to print the last(21st) and second last(20th) characters - the last character(which should not even be there) and and the second last character which should be a space
turns out to be something like this.
A dot
on browser(as the second last character) appears for almost a second and then it disappears. Now, what is going on? Why is this happening?
Please give me directions or else I am going to go out of my mind!
Update:
This is dump of the variable $str
-
string(21) "Vidyalankar Classes "