2011-12-22 89 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); 

这将刚过搜索 “/” 符号之间的第一个模式“文件/“部分。