PHP 删除字符串的最后一部分,由出现的第一个字符决定,从字符串末尾开始

PHP Remove the last part of the string, determined by first character occurrence, starting from the end of the string

字符串总是以连字符结尾,后跟一个可变大小的整数。 例如:

foo-bar-baz-132 another-55-string-961370

如何删除最后一个连字符(从右到左第一次出现)加上右边的任何字符?

试试这个

$string = 'foo-bar-baz-132 another-55-string-961370';
$result = substr ($string , 0, strrpos($string, '-'));
echo $result;

来源