Please tell me how to fix it. It is necessary to write data in 1 line from inputs (writes in 2 lines, but at first I copied the entire file (a) + new data (b) and added it = (aab). And it is necessary that he could read if several lines in the file. Logically, this is what he should do, but for some reason, if the file has an entry on the 2nd + line, it does not find the 1st and 2nd index.How to fix the code so that it writes data to 1 line, and just in case read with 2+ lines? PS: Debuger still has not learned to use (
For readability, added another screen with IDE for you.
Write inputs
<?php $name3=null; $surname3=null; $age=null; if(isset($_POST['name3'],$_POST['surname3'],$_POST['age3'])){ $file=("table.txt"); // $curent=file_get_contents($file);//make copy file - need off! $curent=";".$_POST['name3']."_"; $curent.=$_POST['surname3']."_"; $curent.=$_POST['age3']; file_put_contents($file,$curent,FILE_APPEND|LOCK_EX);} // file_put_contents($file,$curent,FILE_APPEND|LOCK_EX);} // _______ // read data from table.txt ?> Read table.txt
<?php $string1=file("table.txt"); for($i=0;$i<count($string1);$i++){//why did not working if 2+ strings? $datatxt=explode(";", $string1[$i]); for($j=0;$j<count($datatxt);$j++){ $mass=explode("_",$datatxt[$j]); $name="<tr align='center'><td>".$mass[0]."</td>"; $surname="<td>".$mass[1]."</td>"; $age="<td>".$mass[2]."</td></th>"; echo $name.$surname.$age;}} ?> table.txt
Angela_First_16;Lily_Oto_18;Ann_Girl_31 