mardi 9 juin 2020

While fgets php loop [duplicate]

we have code

$fh = fopen('test.txt','r');
// define an eampty array
$data = array();
// read data
while ($line = fgets($fh)) {
    // if the line has some data
   if(trim($line)!=''){
       // explode each line data 
       $line_data = explode('-',$line);
       // push data to array
       $data[]=array('item'=>trim($line_data[0]),'value'=>trim($line_data[1]));   

   }
}
fclose($fh);
// json encode the array
#echo $json_data = json_encode($data);

$line_data[0] = str_replace (' ','-',$line_data[0]);

how to random text test.txt and show in 10 line?

thank you so much




Aucun commentaire:

Enregistrer un commentaire