我正在尝试制作一个if
,该将尝试通过搜索来获取文档的一行。因此,它在文档中搜索"注册商句柄"并获取该行的整个输出。
遇到的问题是我收到此错误:Notice: Undefined index: Registrar Handle in C:'xxxx'xxxx'xxx'xx on line 29
如果有人对此有解决方案,也许可以解释为什么会发生这种情况,那就太好了?
$commandR = "whois ".mysql_result($domain, 0);
$outputR = shell_exec($commandR);
$fhR = fopen('R.txt','w+');
fwrite($fhR,$outputR);
fclose($fhR);
{
//.no
if( strpos(file_get_contents("./R.txt"),$_GET['Registrar Handle'])){
$fhR = fopen('A.txt','r');
$R = fgets($_GET);
fclose($fhA);
Echo $R;
//mysql_query("UPDATE `dom_oversikt`.`server1` SET `Registrar`='".$R."' WHERE `id` = '$id';");
}
您可以循环访问刚刚创建的文件,获取文件的每一行,直到到达末尾,然后回显/返回包含您提到的字符串的行。
$searchedString = 'Registar Handle';
if (($handle = fopen("./R.txt", "r")) !== false) {
while (!feof($handle)) {
$currentLineInFile = fgetss($handle, 4096);
if(false !== strpos($currentLineInFile, $searchedString)){
echo $currentLineInFile;
}
}
fclose($handle);
}
有人可能会争辩说你可以使用 preg_match 而不是 strpos,但它更复杂且速度更慢(根据指向 php 文档本身的 SO 答案)。
关于您的错误,这只是由于数组 $_GET 中没有键"Registar 句柄"。