【发布时间】:2018-11-24 08:05:26
【问题描述】:
有没有更快的方法从字符串 1234R1_t1 的末尾获取第 5 个字符 (R)?
我用这个代码得到它:
$string = "1234R1_t1";
$new_string = substr(substr($string, -5),0,1);
echo $new_string;
【问题讨论】:
-
$str[strlen($string)-5];
有没有更快的方法从字符串 1234R1_t1 的末尾获取第 5 个字符 (R)?
我用这个代码得到它:
$string = "1234R1_t1";
$new_string = substr(substr($string, -5),0,1);
echo $new_string;
【问题讨论】:
$str[strlen($string)-5];
substr("1234R1_t1", -5, 1) 应该这样做。
【讨论】: