PHP获取元标记函数不';不能使用非http

PHP获取元标记函数不';不能使用非http,php,Php,我希望我能得到帮助解决我的问题 我正在使用php get meta tags函数来查看网站列表上是否存在标记,如果存在没有HTTP的域,就会出现问题 理想情况下,如果HTTP不存在,我会想添加它,如果域中有HTTPS,我也需要解决这个问题。这里是我正在使用的代码 如果我登陆到一个域中没有HTTP的站点,我会遇到这个错误 警告:get_meta_tags(www.drhugopavon.com/):无法打开流:第16行的C:\xampp\htdocs\webresp\index.php中没有此类文

我希望我能得到帮助解决我的问题

我正在使用php get meta tags函数来查看网站列表上是否存在标记,如果存在没有HTTP的域,就会出现问题

理想情况下,如果HTTP不存在,我会想添加它,如果域中有HTTPS,我也需要解决这个问题。这里是我正在使用的代码

如果我登陆到一个域中没有HTTP的站点,我会遇到这个错误

警告:get_meta_tags(www.drhugopavon.com/):无法打开流:第16行的C:\xampp\htdocs\webresp\index.php中没有此类文件或目录

$url=array(
'https://www.smilesbycarroll.com/',
'https://hurstbournedentalcare.com/',
'https://www.dentalhc.com/',
'https://www.springhurstdentistry.com/',
'https://www.smilesbycarroll.com/',
“www.drhugopavon.com/”
);
foreach($url作为$url){
$tags=get_meta_标记($url);
if(isset($tags['viewport'])){
回显“$url标记存在”。
”; } 如果(!isset($tags['viewport'])){ 回显“$url标记不存在”。
”; } }
您可以使用此选项检查域是否具有http

foreach($urls as $url){
  if(strpos($url, "http") === FALSE) //check if the url contains http and add it to the beginning of the string if it doesn't 
    $url = "http://" . $url;

  $tags = get_meta_tags($url);
}
另一个更简单的选择是在url中检查:/

 foreach($urls as $url){
      if(strpos($url, "://") === FALSE) //check if the url contains http and add it to the beginning of the string if it doesn't 
        $url = "http://" . $url;

      $tags = get_meta_tags($url);
 }

或者您可以使用类似于Wild Beard的正则表达式

您可以使用它来检查域是否具有http

foreach($urls as $url){
  if(strpos($url, "http") === FALSE) //check if the url contains http and add it to the beginning of the string if it doesn't 
    $url = "http://" . $url;

  $tags = get_meta_tags($url);
}
另一个更简单的选择是在url中检查:/

 foreach($urls as $url){
      if(strpos($url, "://") === FALSE) //check if the url contains http and add it to the beginning of the string if it doesn't 
        $url = "http://" . $url;

      $tags = get_meta_tags($url);
 }

或者您可以使用类似于Wild Beard的正则表达式

您可以使用
parse_url()
检查元素
scheme
是否存在。如果没有,您可以添加:

$urls = array(
    'https://www.smilesbycarroll.com/',
    'https://hurstbournedentalcare.com/',
    'https://www.dentalhc.com/',
    'https://www.springhurstdentistry.com/',
    'https://www.smilesbycarroll.com/',
    'www.drhugopavon.com/'
);

$urls = array_map(function($url) {
  $data = parse_url($url);
  if (!isset($data['scheme'])) $url = 'http://' . $url ;
  return $url;
}, $urls);

print_r($urls);

您可以使用
parse_url()
检查元素
scheme
是否存在。如果没有,您可以添加:

$urls = array(
    'https://www.smilesbycarroll.com/',
    'https://hurstbournedentalcare.com/',
    'https://www.dentalhc.com/',
    'https://www.springhurstdentistry.com/',
    'https://www.smilesbycarroll.com/',
    'www.drhugopavon.com/'
);

$urls = array_map(function($url) {
  $data = parse_url($url);
  if (!isset($data['scheme'])) $url = 'http://' . $url ;
  return $url;
}, $urls);

print_r($urls);

你知道有什么好笑的,我以为这是因为它有http,但我把错误报告(0);在我的原始代码中,它按我希望的那样工作哈哈。

你知道有什么好笑的,我认为这是因为它有http,但我把错误报告(0);在我的原始代码中,它按我希望的那样工作哈哈。

可能重复的可能重复的可能重复的关于
www.http.com
?它将跳过它,因为它确实在url字符串中包含http。我将尝试用另一种可能更适合您的解决方案扩展我的答案
preg_match(“/(^http)/”,$url)
关于
www.http.com
?它将跳过它,因为它在url字符串中确实包含http。我将尝试用另一种可能更适合您的解决方案扩展我的答案
preg_match(“/(^http)/”,$url)