gpt4 book ai didi

PHP file_get_contents foreach

转载 作者:行者123 更新时间:2023-11-29 08:03:49 26 4
gpt4 key购买 nike

我在互联网上发现了一个现有脚本,该脚本可以从 WHOIS 服务器获取数据并提取相关数据(例如到期日期、状态)。由于它已被废弃很长时间,我一直在对其进行修改并创建了自己的 script.php?id=domain.com ,它允许我输入任何域并显示 whois 数据,我遇到的问题是我有 whois.php 文件,我想从 MySQL 数据库中获取域列表,并尝试使用(file_get_contents 到我的 script.php 和foreach),然后使用相关信息更新数据库。我相当确定我已经对除了“Foreach”和“File_get_contents”部分之外的所有内容进行了正确编码,因此我的脚本遇到了错误。

"Warning: Invalid argument supplied for foreach() in /home/user/public_html/mydomain.com/domains/whois.php on line 39"

是我收到的错误。

我的 whois.php 的片段:

include("database.php");
// Select one domain from the database that hasn't been checked yet
$sql = "SELECT domainName from domains WHERE 1 ORDER BY lastChecked ASC";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$domain = $row[0];

if(mysql_num_rows($result) == 0){
die("No domains found in the database.");
}

// Grab the WHOIS information for the domain selected
// ---------------------------------------------------------------
$domainExt = substr($domain, -3); // grab the domain extension


//var_dump($whois);


$arr = array($content);
foreach($arr as $id) {
echo $id, '<br>';
$data = file_get_contents('http://codestrike.net/domains/script.php?id='.$domain.'');
echo $data, '<br>';
}


foreach($data as $whoisline){
if(strstr($whoisline,"Expiration")){
$whoisline = str_replace("Expire Date:","",$whoisline);
$whoisline = trim($whoisline);
$expiration = substr($whoisline,0,11);
}

if(strstr($whoisline,"Status")){
$statusline = $whoisline;
}
}

$status = str_replace("Status:","",$statusline);
$status = trim($status);

Script.php?id=domain.com 工作正常,只需让 whois.php 从我的 MySQL 数据库中查找每个域的到期日期/状态即可。

干杯。

最佳答案

更改:

$data = file_get_contents('http://mydomain.com/domains/script.php?id='.$domain.'');

至:

$data = file('http://mydomain.com/domains/script.php?id='.$domain);

file_get_contents 将整个文件作为单个字符串返回。 file 将其拆分为一个数组,其中每个元素都是文件的一行。

您还需要在第一个 foreach 循环中处理 $data。否则,您每次循环都会覆盖 $data,并且使用它的代码只会获取最后一个。

include("database.php");
// Select one domain from the database that hasn't been checked yet
$sql = "SELECT domainName from domains WHERE 1 ORDER BY lastChecked ASC";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$domain = $row[0];

if(mysql_num_rows($result) == 0){
die("No domains found in the database.");
}

// Grab the WHOIS information for the domain selected
// ---------------------------------------------------------------
$domainExt = substr($domain, -3); // grab the domain extension

//var_dump($whois);

$arr = array($content);
foreach($arr as $id) {
echo $id, '<br>';
$data = file('http://mydomain.com/domains/script.php?id='.$domain);
var_dump($data); echo '<br>';
foreach($data as $whoisline){
if(strstr($whoisline,"Expiration")){
$whoisline = str_replace("Expire Date:","",$whoisline);
$whoisline = trim($whoisline);
$expiration = substr($whoisline,0,11);
}

if(strstr($whoisline,"Status")){
$statusline = $whoisline;
}
}

$status = str_replace("Status:","",$statusline);
$status = trim($status);
}

关于PHP file_get_contents foreach,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23125913/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com