Is there anyway to search a textfile for a string?
Posted: Sat Jan 07, 2006 10:01 am
I have IPs.txt and I want to search if user's IP is banned? How to search? I have spent about 40minutes browsing the php.net doc, but can't find.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$search = "73.13.24.124" //What you are searching for
$lines = file("IPs.txt");
foreach ($lines as $value)
{
if ($search == $value)
//there is a match
}Code: Select all
<?php
if (in_array($ip, file('IPs.txt')) {
echo 'You are banned!';
}
?>Code: Select all
$data = file_get_contents('ip.txt');
if (strpos($ip, $data) !== false) echo 'Banned User';