You can use the parse_url
function, it breaks the URL into its components making it easier to match each component individually:
var_dump(parse_url("https://vine.co/v/"));
// array(3) {
// ["scheme"]=>
// string(4) "http"
// ["host"]=>
// string(7) "vine.co"
// ["path"]=>
// string(3) "/v/"
// }
You can then just check if scheme
, host
and path
match:
function checkVineURL($url) {
$urlpart = parse_url($url);
if($urlpart["scheme"] === "http" || $urlpart["scheme"] === "https") {
if($urlpart["host"] === "vine.co" || $urlpart["host"] === "www.vine.co") {
if(strpos($urlpart["path"], "/v/") === 0) {
return true;
}
}
}
return false;
}
checkVineURL("https://vine.co/v/"); // true
checkVineURL("http://vine.co/v/"); // true
checkVineURL("https://www.vine.co/v/"); // true
checkVineURL("http://www.vine.co/v/"); // true
checkVineURL("ftp://vine.co/v/"); // false
checkVineURL("http://vine1.co/v/"); // false
checkVineURL("http://vine.co/v1/"); // false