Pluda
Pluda

Reputation: 1477

php regex to detect if a url path has folder names

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.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

Upvotes: 1

Views: 474

Answers (2)

mario
mario

Reputation: 145472

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.

Upvotes: 4

Qtax
Qtax

Reputation: 33908

Use PHPs parse_url()

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

Upvotes: 5

Related Questions