I have found a problem with the following lines of PHP code:
$stripped = 'some string';
$stripped = substr($stripped, 0, strrpos($stripped, ' '));
The intent was to strip off the last token of text. When I traced the execution of the code, I found that it was not working. In order to make it work, I had to change the code to the following:
$stripped = 'some string';
$truncate_length = strrpos($stripped, ' ');
$stripped = substr($stripped, 0, $truncate_length);
Why would the first version of this code not work? I have never felt it necessary before to avoid function composition like the above example shows as necessary.
It does work. Maybe a misspelling ?
Also, remember that if there is no ' '
(space) found with strrpos, you will get false
as return value and will kill $stripped