2013-05-22 1 views
2

선택한 행을 복사큰 텍스트 파일을 읽고 내가 <a href="http://standards.ieee.org/develop/regauth/oui/oui.txt" rel="nofollow">here</a>에서 데이터베이스 테이블을 작성해야 다른 파일

그래서, curl 명령을 사용하여 서버의 폴더에 같은 파일을 복사. 위의 텍스트 파일에서 00-00-00 (hex) XEROX CORPORATION, 00-00-01 (hex) XEROX CORPORATION 등을 검색해야합니다. 조직의 첫 번째 줄과 16 진수 값만 다른 텍스트 파일로 복사해야합니다.

PHP로 어떻게 할 수 있습니까?

답변

1
<?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); 
1

이 하나

<?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 

    ?> 
0
<?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); 
} 

?>

시도
관련 문제