簡體   English   中英

PHP preg_match url

[英]PHP preg_match url

我在PHP中遇到了preg_match的問題。

我有網址:

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

我需要網址:

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

我必須刪除:

w867/
c3233/
etc.

您不一定需要使用preg_match。 parse_url()可以完成這項工作。

http://us.php.net/manual/en/function.parse-url.php

只需確保在沒有您不想要的部分的情況下將其全部連接起來。

你可以嘗試這樣的模式:

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

然后使用str_replace,你可以: $string = str_replace('/'.$matches[2], '', $string);

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

這將在“file /”部分之后的“/”符號之間搜索第一個模式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM