Reading Fixed-Width Delimited Data
<?php
$flatfile = "data.txt";
if (file_exists ($flatfile)){
$rows = file ($flatfile);
for ($i = 0; $i < count ($rows); $i++){
$item = substr ($rows[$i],0,20);
$amount = substr ($rows[$i],20,40);
echo "Item: " . rtrim ($item) . " has " . rtrim ($amount) . " unit (s) left.<br />";
}
} else {
echo "File does not exist.";
}
?>
Related examples in the same category