Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果我没有';我没有关于网站的协议信息_Php_Html - Fatal编程技术网

Php 如果我没有';我没有关于网站的协议信息

Php 如果我没有';我没有关于网站的协议信息,php,html,Php,Html,我使用的代码是: $url = "example.com"; $code = file_get_contents("http://www.".$url); if (!$code) { $code = file_get_contents("https://www.".$url); } 我不知道每个URL是以http还是https开头。我的数据库中保存了1000个URL。有什么建议吗?有些相关。考虑到您的数据库相当不完整,因为URL不是完全限定的,我倾向于编写一个简短的例程来更新数据

我使用的代码是:

$url = "example.com";
$code =  file_get_contents("http://www.".$url);
if (!$code) {
    $code =  file_get_contents("https://www.".$url);
} 
我不知道每个URL是以
http
还是
https
开头。我的数据库中保存了1000个URL。有什么建议吗?

有些相关。考虑到您的数据库相当不完整,因为URL不是完全限定的,我倾向于编写一个简短的例程来更新数据库以备将来使用

<?php
$url = 'example.com';
$variations[] = 'http://'.$url;
$variations[] = 'https://'.$url;
$variations[] = 'http://www.'.$url;
$variations[] = 'https://www'.$url;
foreach($variations as $v){
  // Check variation with function from answer linked above
  if(urlOK($v)){
    // code to update database row
    // or if you don't want to do that
    $code =  file_get_contents($v);
  }
}

您必须使用反复试验,因为您的数据不是URL,而是可能被解释为主机名的字符串。如果找不到
https
资源,您可以回退到
http
,您可以尝试这两种方法。或者反之亦然。你可以在这些URL上循环,如果有条件,你可以知道哪个是working@Federkun你能帮我填一下if-else语句吗。因为当我尝试时,它会导致错误和页面停止执行。您需要什么帮助?你试过什么?用代码编辑你的问题