PHP/File Directory/fscanf
Acceptable Format Values for fscanf()
%b Binary number
%c Single character
%d Signed decimal number
%u Unsigned decimal number
%f Float
%o Octal
%s String
%x Hexadecimal Number
fscanf.php
<?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);
?>
Reading Formatted Text Using fscanf()
<?php
$fr = @fopen("data.txt", "r");
if(!$fr) {
echo "Error! Couldn"t open the file.<BR>";
exit;
}
while(!feof($fr)) {
fscanf($fr, "%u-%u-%u %s %s", &$month, &$day,
&$year, &$first, &$last);
echo "First Name: $first<BR>";
echo "Last Name: $last<BR>";
echo "Birthday: $month/$day/$year<BR>";
}
fclose($fr);
?>