[英]PHP preg_match url
I have a problem with preg_match in PHP. 我在PHP中遇到了preg_match的问题。
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. 您不一定需要使用preg_match。 parse_url() can do the job.
parse_url()可以完成这项工作。
http://us.php.net/manual/en/function.parse-url.php 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);
然后使用str_replace,你可以:
$string = str_replace('/'.$matches[2], '', $string);
preg_replace("|file/\w+/|", "file/", $url);
这将在“file /”部分之后的“/”符号之间搜索第一个模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.