开发者

php regex to detect if a url path has folder names

开发者 https://www.devze.com 2023-03-06 03:27 出处:网络
One of the things I\'ve really trouble is with regex, I just dont understand it :-( So, I just need to check if one url has or not folder names after .com or .net or .whatever and if it has, isolate

One of the things I've really trouble is with regex, I just dont understand it :-(

So, I just need to check if one url has or not folder names after .com or .net or .whatever and if it has, isolate them in a variable, example

www.mysite.com (perfect) and www.开发者_C百科mysite.com/folder or http://mysubdomain.mysite.com/folder/folder

the goal is to be able of isolate the folder names in a variable to be used as a path for upload


Use PHPs parse_url()

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


You can use parse_url() more easily for that.

print_r(parse_url("http://mysubdomain.mysite.com/folder/folder"));

Gives you:

Array
(
    [scheme] => http
    [host] => mysubdomain.mysite.com
    [path] => /folder/folder
)

And then just take the path out of that.

0

精彩评论

暂无评论...
验证码 换一张
取 消