Home>Article>Backend Development> PHP uses the fgets() function to read the string line by line and then uses the explode() function to split the string into array instances.
fgets()FunctionRead a line from the file pointer. Theexplode() function breaks up thestringinto anarray.
The following example code first uses the fgets() function to read the string line by line and then uses the explode() function to split the string into an array. The code is as follows
"; $str = explode("|",$line); //print_r($str); $file_type = $str [0]; $dir_name = $str [1]; $file_name = $str [2]; $file_size = $str [3]; $create_time = $str [4]; echo $file_type; echo "
"; echo $dir_name; echo "
"; echo $file_name; echo "
"; echo $file_size; echo "
"; echo $create_time; echo "
"; } fclose($f); ?>
The above is the detailed content of PHP uses the fgets() function to read the string line by line and then uses the explode() function to split the string into array instances.. For more information, please follow other related articles on the PHP Chinese website!