PHP/File Directory/fscanf

Материал из Web эксперт
Перейти к: навигация, поиск

Acceptable Format Values for fscanf()

   <source lang="html4strict">

%b Binary number

%c Single character

%d Signed decimal number

%u Unsigned decimal number

%f Float

%o Octal

%s String

%x Hexadecimal Number

 </source>
   
  


fscanf.php

   <source lang="html4strict">

<?php

  $fh = fopen("data.txt", "r");
  while ($user = fscanf($fh, "%d-%d-%d")) {
     list ($part1,$part2,$part3) = $user;
     print $part1;
     print $part2;
     print $part3;
     
  }
  fclose($fh);

?>

 </source>
   
  


Reading Formatted Text Using fscanf()

   <source lang="html4strict">

<?php

    $fr = @fopen("data.txt", "r");
    if(!$fr) {
         echo "Error! Couldn"t open the file.
"; exit; } while(!feof($fr)) { fscanf($fr, "%u-%u-%u %s %s", &$month, &$day, &$year, &$first, &$last); echo "First Name: $first
"; echo "Last Name: $last
"; echo "Birthday: $month/$day/$year
"; } fclose($fr);

?>

 </source>