Lets assume that Joe Blow is selling books online. Joe has a plain text file filled with data about his books that is tab separated. He has written a short script that will (should) let him edt that data. But for some stupid reason the php based editor file includes a single blank line each time it edits the text file. If Joe Blow included that php file in a post on a php forum board, what are the chances that some other Joe could help him see the error of his ways and resolve the elusive "nothing".
The plain text file resembles the following:
001 Title Description Price each would be tab separated
002 Title2 Description2 Price2 again this should be separated
003 So on And so forth Price3 Another line of tab separated
004 Get The Point Price4 So what do you think
The actual script would read something like the following.
<?
$file = file("items.dat");
foreach($file as $value){
$fi = preg_split("/[\t]/", $value);
$titles[$fi[0]] = $fi;
}
echo "Choose the item number you would like to edit.<br><br>";
foreach($titles as $key=>$value){
echo "<a href=\"?id=$key\">$key</a>      ";
if ($_POST['0']){
$titles[$POST['0']] = $POST;
foreach($titles as $values){
$ntitles[] = implode("\t", $values);
}
if (is_array($ntitles)){
$newtitles = implode("\n", $ntitles);
}
$fid = fopen("items.dat", "w");
fwrite($fid, $newtitles);
fclose($fid);
}
if ($_GET['id']){
echo <<<THERE
<br><Br>
<table width="458" border="0">
<tr>
<td width="307" rowspan="20"><div align="right"><FORM method="POST">
THERE;
$named[0] = "Item Number";
$named[1] = "Title";
$named[2] = "Description";
$named[3] = "Price";
$named[4] = "Long Description";
foreach($titles[$_GET['id']] as $key=>$value){
echo "$named[$key] : <input type=\"text\" name=\"$key\" value=\"$value\"><br>";
}
echo <<<THERE
<br><br><br>
<input type="submit" value="Submit">
</FORM></div></td>
</tr>
</table>
THERE;
}
?>
Any help would be greatly appreciated.