[英]Compare IP address in textfile. How to search?
I have a textfile there the content is following: 我有一个文本文件,内容如下:
TME: 1316179740.2558|FNE: blog-comments.php|MSG: Kommenterade "ett nyare blogginlägg"-blogginlägget|IPA: ce8bf851d2b1bb1d7f7b24d3656f3d4c90d4ac88c50537e065843b7a0a6c8c236eef76d5814f0782f864209da2b8be1be0d449e86edbcd478847ccbe0189b61f
... and so on. ... 等等。 IPA stands for IP address and is the visitor IP address.
IPA代表IP地址,是访客IP地址。 I want to compare this information with the visitors real IP address, so to speak, to get correct information from the file for the visitor.
我想将此信息与访问者的真实IP地址进行比较,可以这么说,以从访问者的文件中获取正确的信息。 How do I accomplish this?
我该如何完成?
Thanks in advance. 提前致谢。
You could use a regular expression to grab out the important portion and compare that... 您可以使用正则表达式来提取重要部分并进行比较...
if (preg_match_all('/IPA:\s*([a-f\d]+)/i', $subject, $matches, PREG_SET_ORDER)) {
// your values will be in the $matches array here
// with the actual IP hash in $matches[$i][1]
}
I don't know how long the IPA is, or what the ending delimiter is, so this will grab all hexadecimal characters until they run out. 我不知道IPA多长时间,或者结尾的定界符是什么,所以它将捕获所有十六进制字符,直到用完为止。
Try 尝试
$array = file('textfiles/activity/'.$_GET['d'].'.txt');
foreach($array AS $key => $test) {
$info = explode('|', $test);
$info_date = explode('TME: ', $info[0]);
$info_msg = explode('MSG: ', $info[2]);
$hashed_ip = explode('IPA: ', $info[3]);
if(trim($hashed_ip[1]) == hash('whirlpool', $_SERVER['REMOTE_ADDR'])) {
echo '<b>'.date('H:i', $info_date[1]).'</b>: '.$info_msg[1].'<br>';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.