Php 如何检查阵列中的域?
我整个下午都在做这件事,我想不出来。我在这个问题上抛出了6种不同的解决方案,但我无法让它起作用 情况:上传页面。我们有一个数组,该数组根据保存所需域名的局部变量来解析和匹配元文件。我们希望两者匹配。因此,该检查失败,并分配“external=yes”,认为域之间没有任何关系,并继续执行脚本的其余部分当域与包含“相同”域名(带有url参数)的局部变量正确匹配时,我们非常希望external=no 因此,它根据中包装的变量检查数组(解析文件)!在数组中。比如说,domain.com/somepage.html在我们的局部变量中,由于/somepage.html,它无法匹配 默认情况下,代码如下所示:Php 如何检查阵列中的域?,php,arrays,validation,preg-match,string-matching,Php,Arrays,Validation,Preg Match,String Matching,我整个下午都在做这件事,我想不出来。我在这个问题上抛出了6种不同的解决方案,但我无法让它起作用 情况:上传页面。我们有一个数组,该数组根据保存所需域名的局部变量来解析和匹配元文件。我们希望两者匹配。因此,该检查失败,并分配“external=yes”,认为域之间没有任何关系,并继续执行脚本的其余部分当域与包含“相同”域名(带有url参数)的局部变量正确匹配时,我们非常希望external=no 因此,它根据中包装的变量检查数组(解析文件)!在数组中。比如说,domain.com/somepage
$match_urls = explode(",", strtolower($siteconfig["urls_list"]));
$FileInfo = array();
$FileInfo = ParseFile("$file_dir/$file_name");
$urls = $FileInfo[0];
$filehash = $FileInfo[1];
$creationdate = $FileInfo[2];
$internalname = $FileInfo[3];
if (!in_array($urls, $match_urls, 1)) {
$external = 'yes'; <-- domain fails to match, so we only get this (not good)
} else {
$external = 'no'; <-- We need this for matched domain (parsed & local variable)
}
并在这方面尝试了许多变化:
if (!in_array($urls, CheckUrls() === true, 1)) {
$external = 'yes';
} else {
$external = 'no';
}
我也试过传球:
$domain = "http://website.com/somepage.html";
$checkit = preg_match('{^http://[\w\.]*website.com/}i', $domain));
致:
在过去的4个小时里,我一直在用var_甩我的路,我试了又试,试了又试。。我想不出来。我做错了什么
这在匹配中非常有效:
preg_match('{^http://[\w\.]*website.com/}i', $domain)
但我无法实现它!在_array()中,它让我抓狂。我试图传递真/假/空,但没有用
再次感谢 检查URL没有意义,因为它返回的是布尔值而不是数组。Preg_match函数将在任何匹配(或否)的情况下返回1或0,或者在发生某些情况时返回false,而不是匹配本身。如果要获取匹配列表,必须传递第三个参数(数组)并返回该参数以用于in_数组函数,如下所示:
函数checkURL($domain)
{
$matches=[];
preg_match({^http://[\w\.]*website.com/}i',$domain,$matches);
返回$matches;
}
那么,只要做:
$external='no';
如果(!in_数组($URL,checkURL($domain),true)){
$external='yes';
}
请参阅以下内容以正确使用preg_match:
if (!in_array($urls, $checkit, 1)) {
$external = 'yes';
} else {
$external = 'no';
}
preg_match('{^http://[\w\.]*website.com/}i', $domain)