时间:2021-07-01 10:21:17 帮助过:6人阅读
取出文件的内容,根据换行跟分隔符切分数据
取出文件的内容,根据换行跟分隔符切分数据
说的稍微详细点!!!
说的稍微详细点!!!
text.txt
192.168.1.2---xxx.com192.168.1.3---xx.com
$ip = isset($_GET['ip'])? $_GET['ip'] : '';$domain = isset($_GET['domain'])? $_GET['domain'] : '';if($ip=='' && $domain==''){ exit('ip and domain is empty');}$file = 'test.txt';$filedata = file_get_contents($file);$arr1 = array();$arr2 = array();$data = explode("\n", $filedata);foreach($data as $k=>$v){ $tmp = explode('---', $v); $arr1[$tmp[0]] = $tmp[1]; $arr2[$tmp[1]] = $tmp[0];}if($ip!=''){ if(isset($arr1[$ip])){ echo $ip.'---'.$arr1[$ip]; }else{ echo 'ip not exists'; }}elseif($domain!=''){ if(isset($arr2[$domain])){ echo $arr2[$domain].'---'.$domain; }else{ echo 'domain not exists'; }}
text.txt
192.168.1.2---xxx.com192.168.1.3---xx.com
$ip = isset($_GET['ip'])? $_GET['ip'] : '';$domain = isset($_GET['domain'])? $_GET['domain'] : '';if($ip=='' && $domain==''){ exit('ip and domain is empty');}$file = 'test.txt';$filedata = file_get_contents($file);$arr1 = array();$arr2 = array();$data = explode("\n", $filedata);foreach($data as $k=>$v){ $tmp = explode('---', $v); $arr1[$tmp[0]] = $tmp[1]; $arr2[$tmp[1]] = $tmp[0];}if($ip!=''){ if(isset($arr1[$ip])){ echo $ip.'---'.$arr1[$ip]; }else{ echo 'ip not exists'; }}elseif($domain!=''){ if(isset($arr2[$domain])){ echo $arr2[$domain].'---'.$domain; }else{ echo 'domain not exists'; }}