Php preg_match pinterest用户名url有问题
请帮助我匹配pinterest用户名url时使用的语句是 $url= preg|u match(“^http(s)://pinterest.com/(.*))$|i“,$url)Php preg_match pinterest用户名url有问题,php,regex,preg-match,Php,Regex,Preg Match,请帮助我匹配pinterest用户名url时使用的语句是 $url= preg|u match(“^http(s)://pinterest.com/(.*))$|i“,$url) 但是preg_match result返回0您缺少preg_match函数的第三个参数 $url = "http://pinterest.com/username"; preg_match("|^http(s)?://pinterest.com/(.*)?$|i", $url, $match); print_r($
但是preg_match result返回0您缺少
preg_match
函数的第三个参数
$url = "http://pinterest.com/username";
preg_match("|^http(s)?://pinterest.com/(.*)?$|i", $url, $match);
print_r($match);
导致
Array
(
[0] => http://pinterest.com/username
[1] =>
[2] => username
)
或在if语句中:
$url=”“
if(preg|u match(“| ^http(s)://pinterest.com/(.*))$i“,$url,$match)){
//真的
}
输出:
真的
你还想干什么?没人说需要逃离点。 因此,更正确的代码如下所示:
$url = "https://pinterest.com/username";
preg_match("|(?:https?://)(?:www\.)?pinterest\.com/(.+)/?|i", $url, $match);
它将返回用户名。我不知道用户名有pinterest的规则,所以我只匹配斜杠中的所有内容
它将与以下链接一起工作:
不要使用此正则表达式进行验证将第三个参数添加到preg\u match函数中。您想做什么?看看它是否匹配,或者你想找到用户名?
$url = "https://pinterest.com/username";
preg_match("|(?:https?://)(?:www\.)?pinterest\.com/(.+)/?|i", $url, $match);