我需要从这里创建一个数据库表:
因此,我使用 curl 命令将相同的文件复制到服务器文件夹。我需要00-00-00 (hex) XEROX CORPORATION, 00-00-01 (hex) XEROX CORPORATION
从上面的文本文件中检索等。我只需要将十六进制值和组织的第一行复制到另一个文本文件中。
我怎样才能用 PHP 做到这一点?
<?php
// open the input and the output
$fp = fopen("http://standards.ieee.org/develop/regauth/oui/oui.txt","r");
$out = fopen("somefile.txt","w");
while($rec = fgets($fp)){
// check to see if the line contains '(hex)'
if (strpos($rec, '(hex)') !== false){
// if so write it out
fputs($out, $rec."\n");
}
}
fclose($fp);
fclose($out);
试试这个
<?php
$i = 1;
$a_line = "";
$first_line = "";
$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
if($i == 1)
// here you have first line
$first_line = $buffer;
else {
// check the $buffer contains the substring (hex) and XEROX CORPORATION
// if it contains put it in another variable
$a_line .= $buffer;
}
}
if (!feof($handle)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}
// finally write the $first_line to a header file
// then write $a_line to another file
?>
<?php
error_reporting(0);
$fs=fopen("1.txt", "r");
$ft=fopen("2.txt", "w");
if ($fs==NULL)
{
echo "Can't Open Source File ...";
exit(0);
}
if ($ft==NULL)
{
echo "Can't Open Destination File ...";
fclose ($fs);
exit(1);
}
else
{
while ($ch=fgets($fs))
fputs($ft, $ch);
fclose ($fs);
fclose ($ft);
}
?>