作者sinstar (sinstar)
看板PHP
標題[請益] 抓取字串中 特定字元前後字串 的問題
時間Fri Nov 2 21:14:18 2007
我想抓取字串中 某個字之後 且 某個字之前 的字串
例如 1158/
1794529955_c83awegba_o.jpg
我只要黃色的部份
由於其中數字的位數是會改變的
參考了手冊後想說用strstr來寫
寫出下面這樣的code
$match = '2108/1797529955_c83a0ed7ba_s.jpg';
$imgid = strstr(strstr($match, '/'),'_',true);
但是卻回應參數錯誤
請問出了什麼問題了嗎?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.64.141.223
※ 編輯: sinstar 來自: 61.64.141.223 (11/02 21:25)
推 kasase:strstr returns the portion of string 11/02 22:28
→ kasase:而且他只接受兩個參數 11/02 22:30
推 nahp:除了以上,也可以用正規表示來做唷 11/02 22:46
推 michaelz:preg_match('/\/(\d+)_/', $match, $result); 11/03 13:24