在php中提取字符串的一部分

阿德里安·斯托克(Adrian Stoker)

我特别需要从PHP输入中剥离字符。

例如,我们有一个版本号,而我只需要它的最后一部分。

鉴于14.1.2.123我只需要123
鉴于14.3.21我只需要21

有没有一种方法可以让我在PHP中获得这些数字?

ug田玻色

你可以试试这个-

$temp = explode('.', $version); // explode by (.)
echo $temp[count($temp) - 1]; // get the last element

echo end($temp);

或者

$pos = strrpos($version, '.'); // Get the last (.)'s position
echo substr(
     $version, 
     ($pos + 1), // +1 to get the next position
     (strlen($version) - $pos) // the length to be extracted
); // Extract the part

strrpos()substr()strlen()explode()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章