1.php intercepts the content behind specific characters
You can use the function strripos to get the first occurrence of a string in another string.
$number = '1_0'; $result = substr($number,strripos($number,"_")+1); echo $result;
Result output 0
$number = '1_0'; $result = substr($number,0,strrpos($number ,"_")); echo $result;
Ps: substr ($ number, strripos ($ number, "_") + 1) where +1 1 is the next 1 byte, if it is Chinese, a Chinese character +3, Chinese characters in the string account for three bytes , If you add +1 on the basis of Chinese characters, it will be garbled.
You can use the function strripos to get the first occurrence of a string in another string.
$number = '1_0'; $result = substr($number,strripos($number,"_")+1); echo $result;
Result output 0
$number = '1_0'; $result = substr($number,0,strrpos($number ,"_")); echo $result;
Ps: substr ($ number, strripos ($ number, "_") + 1) where +1 1 is the next 1 byte, if it is Chinese, a Chinese character +3, Chinese characters in the string account for three bytes , If you add +1 on the basis of Chinese characters, it will be garbled.