URL: http://www2.zippyshare.com/v/hlA8HjA9/file.html
I just create a database and I know how to get the filename after the /v/ but now I need to add another string to my database. It's a server. They've got subdomain as a server and each file is on different server for example www3.zippyshare or www73.zippyshare.com
Now I've got something like this:
$myLink = $_POST['url'];
$var_url = parse_url($myLink);
$var_parts = explode('.', $var_url['host']);
$var = var_parts[0];
But the link save the "v" to my database..
I don't know how to get the subdomain and then skip the www so I will add only the number to my database.
I am not sure if I write it clear enough but I will be really happy if someone could help me.
I'd use this regular expression:
/^(?:https?:\/\/)?([\da-z-]+)\.[a-z]+\.[a-z\.]{2,6}\/v\/[a-z0-9].+\/([a-z0-9]+\.[a-z]+)$/
Do it in PHP like this:
$url = "http://www2.zippyshare.com/v/hlA8HjA9/file.html";
$pattern = "/^(?:https?:\/\/)www([\d0-9-]+)\.[a-z]+\.[a-z\.]{2,6}\/v\/([a-z0-9\/\.].+)$/";
preg_match($pattern, $url, $matches);
list(, $server, $file) = $matches;
The server will then be in $server
, the filename will be in $file
.
Proof: https://3v4l.org/hHWRm