2012-10-04 32 views
-1
$ranges = array('10.20.8.0-10.20.14.254', '192.168.0.2-192.168.0.254'); 
foreach ($ranges as $iprange) { 
    list($lowerip, $highip) = explode('-', $iprange); 
    $remoteip = ip2long($_SERVER['REMOTE_ADDR']); 
    if (ip2long($lowerip) <= $remoteip && $remoteip <= ip2long($highip)) { 

    } 
} 

在上面的例子中,你将如何解压缩文件的所有字符串,并把它们放入数组?将文件中的所有字符串转换为数组?

$ranges = array('include file.txt) 

只有给我的错误。你会如何纠正它看起来像我上面的?

+0

你试图寻找到的(http://php.net/manual/en/ref.filesystem.php) – Gordon

回答

2

PHP的file()命令会带来的全部内容到一个数组:

$ranges = file('file.txt'); 

或者,你可以使用PHP的file_get_contents()然后explode()上换行符(假设只是\n为新行;如果这不起作用,试试Windows风格\r\n):

$ranges = explode("\n", file_get_contents('file.txt')); 
+0

请务必使用“[PHP手册?] \ n“就像@newfurniturey一样,而不是'\ n'(注意双引号)。 – SJFrK