I need to create a database table from here:
So, I copied the same file to a server folder using curl command. I need to retrieve 00-00-00 (hex) XEROX CORPORATION, 00-00-01 (hex) XEROX CORPORATION etc. from the above text file. I need to copy only the hex values and the first line of organisation to another text file.
How can I do it with 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);
Try this one
<?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
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With