2012-10-04 33 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