2011-09-03 47 views
3

我的模式是:/(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g 和數據:http://gskinner.com/RegExr/?2ujor未知的修飾的 'g' PHP正則表達式錯誤

和PHP代碼:

$regexp = ' /(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g'; 
if(preg_match("$regexp", $input, $matches, PREG_SET_ORDER)) { 
for($i=0;$i<14;$i++){ 
echo '--->'.$i.'-->'.$matches[0][$i]; 

}} 

結果:警告:的preg_match()[function.preg-匹配]:未知的修飾 'G'

$regexp = ' /(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g'; 
if(preg_match_all("$regexp", $input, $matches, PREG_SET_ORDER)) { 
for($i=0;$i<14;$i++){ 
echo '--->'.$i.'-->'.$matches[0][$i]; 

}} 

結果:警告:preg_match_all()[function.preg-全匹配]:未知 修改 'G'

這個解決方案沒有奏效! :| "Unknown modifier 'g' in..." when using preg_match in PHP?

我該怎麼辦?

+0

完全無關的問題,但你應該使用'\ .'匹配點。 –

回答

5

切換到preg_match_all是正確的,現在你需要做的是從你的正則表達式中刪除 'G':

$regexp = ' /(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/'; 
+1

我想要所有匹配的字符串!刪除g只返回第一個匹配的字符串$ matches [0] [0] – Amino

2

There's no g modifier

刪除G和它會工作

$regexp = '/(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/'; 
+1

without G它只返回第一個匹配的字符串!
---> 0 - > productimages/Routers/v/CISCO1941.jpg ---> 1 - > productimages/---> 2 - > Routers ---> 3 - >/v/- - > 4 - > CISCO1941 ---> 5 - > JPG ---> 6 - > ---> 7 - > ---> 8 - > ---> 9 - > - - > 10 - > ---> 11 - > ---> 12 - > ---> 13 - > – Amino

+0

@Amino:使用preg_match_all() – genesis

相關問題