Created
June 28, 2012 04:00
-
-
Save dervn/3008953 to your computer and use it in GitHub Desktop.
ip抽取实验脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*************************************************************************** | |
* | |
* Copyright (c) 2012 Baidu.com, Inc. All Rights Reserved | |
* | |
**************************************************************************/ | |
/** | |
* @file ip.php | |
* @author dn([email protected]) | |
* @date 2012/06/27 19:01:58 | |
* @brief | |
* | |
**/ | |
ini_set("memory_limit", "512M"); | |
$handle = @fopen("2", "r"); | |
if ($handle) { | |
$arr_names = getNames(); | |
while (($buffer = fgets($handle)) !== false) { | |
$arr = explode(' ',$buffer); | |
if(!empty($arr) && intval($arr[0]) > 7){ | |
$name = ''; | |
foreach($arr_names as $var){ | |
if(trim($arr[1]) == trim($var[0])){ | |
$name .= $var[1] .','; | |
} | |
} | |
$name = trim($name,','); | |
//echo $name; | |
$content = trim($buffer)." ".$name; | |
file_put_contents('5',$content,FILE_APPEND); | |
file_put_contents('5',"\n",FILE_APPEND); | |
} | |
} | |
if (!feof($handle)) { | |
echo "Error: unexpected fgets() fail\n"; | |
} | |
fclose($handle); | |
} | |
function getNames () { | |
$ret = array(); | |
$handle = fopen("4","r"); | |
while (($buffer = fgets($handle)) !== false) { | |
$arr = explode(' ',trim($buffer)); | |
array_push($ret,$arr); | |
} | |
if (!feof($handle)) { | |
echo "Error: unexpected fgets() fail\n"; | |
} | |
fclose($handle); | |
return $ret; | |
} | |
/* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment