我們用織夢做網站,有時候需要用php截取特定字符前面和后面的內容,可以用以下方法來實現
1、php 截取特定字符后面的內容
可以使用函數strripos,獲取一個字符串在另一個字符串中第一次出現的位置。
$number = '1_0';$result = substr($number,strripos($number,"_")+1);echo $result;
//該程式輸出0
2、php 截取特定字符前面的內容
可以使用函數strrops,獲取一個字符串在另一個字符串中最后一次出現的位置。
$test = '1_0';$result = substr($test,0,strrpos($test,"_"));echo $result;
該程式輸出1
新聞熱點
疑難解答