我特别需要从PHP输入中剥离字符。
例如,我们有一个版本号,而我只需要它的最后一部分。
鉴于14.1.2.123
我只需要123
鉴于14.3.21
我只需要21
有没有一种方法可以让我在PHP中获得这些数字?
你可以试试这个-
$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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句