I have a problem with preg_match in PHP.
I have URLs:
http://mysite.com/file/w867/2612512232
http://mysite.com/file/c3233/2123255464
etc.
I need URLs:
http://mysite.com/file/2612512232
http://mysite.com/file/2123255464
I must remove:
w867/
c3233/
etc.
You don't necessarily need to use preg_match. parse_url() can do the job.
http://us.php.net/manual/en/function.parse-url.php
Just make sure to concatenate it all against without the part you don't want.
you could try a pattern like this:
"/(.*)\\/([^/])*\\/(.*)/"
and then with str_replace you can: $string = str_replace('/'.$matches[2], '', $string);
preg_replace("|file/\w+/|", "file/", $url);
这将在“file /”部分之后的“/”符号之间搜索第一个模式。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.