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

Jac*_*nto 0 php string

现在我在我的字符串上使用它,substr($row->review[$i] , 0, 120)但我想更进一步,在我限制它之后找到最后一个时期并取出所有内容.有任何想法吗?

Gol*_*rol 5

$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;
Run Code Online (Sandbox Code Playgroud)

  • 全部在一行:`if(($ p = strrpos($ a,'.'))!== false)$ a = substr($ a,0,$ p + 1);` (2认同)