如何将其更改为允许对Vine使用HTTP或HTTPS?
$vineURL = 'https://vine.co/v/';
$pos = stripos($url_input_value, $vineURL);
if ($pos === 0) {
echo "The url '$url' is a vine URL";
}
else {
echo "The url '$url' is not a vine URL";
}发布于 2014-12-11 17:58:29
您可以使用parse_url函数,它将URL分解成它的组件,这样可以更容易地单独匹配每个组件:
var_dump(parse_url("https://vine.co/v/"));
// array(3) {
// ["scheme"]=>
// string(4) "http"
// ["host"]=>
// string(7) "vine.co"
// ["path"]=>
// string(3) "/v/"
// }然后,只需检查scheme、host和path是否匹配:
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发布于 2014-12-11 17:47:41
只需去掉"https://“,并更改您的if语句一点.就像这样:
$vineURL = 'vine.co/v/';
if(stripos($user_input_value, $vineURL) !== false) {
echo "This is a vine URL";
} else {
echo "This is not a vine URL";
}发布于 2014-12-11 17:58:00
像这样的用户RegEx
if (preg_match("/^http(s)?:\/\/(www\.)?vine\.co\/v\//", $url)) {
echo "This is a vine URL";
} else {
echo "This is not a vine URL";
}https://stackoverflow.com/questions/27429112
复制相似问题