在最后一段时间之后减去所有东西

Right now I am using this on my string substr($row->review[$i] , 0, 120) but I would like to take it a bit further and after I limit it find the last period and take out everything after. Any ideas?

$a = 'string you got with substr. iwehfiuhewiufh ewiufh . iuewfh iuewhf 
     iewh fewhfiu h. iuwerfh iweh f.ei wufh ewifh iuhwef';

$p = strrpos($a, '.');
if ($p !== false) // Sanity check, maybe there isn't a period after all.
  $a = substr($a, 0, $p + 1 /* +1 to include the period itself */);
echo $a;

See the documentation on strrpos().

As Alex pointed out, strrpos() can find the location of the last occurrence of a sub-string:

$offset = strrpos($row->review[$i],'.');

Then you use this offset to slice off the last part of the main variable:

echo substr($row->review[$i],$offset);

This is a rather easy solution and will work no matter how long the extension or how many dots or other characters are in the string.

$filename = "abc.def.jpg";

$newFileName = substr($filename, 0 , (strrpos($filename, ".")));

//$newFileName will now be abc.def

Basically this just looks for the last occurrence of . and then uses substring to retrieve all the characters up to that point.

It's similar to one of your googled examples but simpler, faster and easier than regular expressions and the other examples. Well imo anyway. Hope it helps someone.