推 sinstar:謝謝大家的指教 學到很多方法 11/04 23:00
※ 引述《sinstar (sinstar)》之銘言:
: 我想抓取字串中 某個字之後 且 某個字之前 的字串
: 例如 1158/1794529955_c83awegba_o.jpg
: 我只要黃色的部份
: 由於其中數字的位數是會改變的
: 參考了手冊後想說用strstr來寫
: 寫出下面這樣的code
: $match = '2108/1797529955_c83a0ed7ba_s.jpg';
: $imgid = strstr(strstr($match, '/'),'_',true);
: 但是卻回應參數錯誤
: 請問出了什麼問題了嗎?
: 謝謝
可以用兩個split()來把前後切掉就好啦~
$str = '1158/1794529955_c83awegba_o.jpg';
list(, $tmp) = split('/', $str, 2);
list($imgid, ) = split('_', $tmp);
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.13.240.33
※ 編輯: toodoo 來自: 163.13.240.33 (11/03 14:18)