2011-12-22 86 views
0

我在PHP中遇到preg_match問題。PHP preg_match url

我有網址:

http://mysite.com/file/w867/2612512232 
http://mysite.com/file/c3233/2123255464 
etc. 

我需要的URL:

http://mysite.com/file/2612512232 
http://mysite.com/file/2123255464 

我必須刪除:

w867/ 
c3233/ 
etc. 

回答

0

你可以嘗試這樣的模式:

"/(.*)\/([^/])*\/(.*)/"

,然後用str_replace函數,您可以:$string = str_replace('/'.$matches[2], '', $string);

0
preg_replace("|file/\w+/|", "file/", $url); 

這將剛過搜索 「/」 符號之間的第一個模式「文件/「部分。