php - open a file and get the content in an array -


in php how file path , return content in array? lets have file: file.txt have path:path_file, , file tsv this:

a0 b0 a1 b1 a2 b2 ... 

how can access file , put content in array this:

array( array(a0,b0), array(a1,b1), array(a2,b2),  ) 

how can file content use of path?

 function get_content_file($path_file)  {  $data[];   //open file path   //read file content   //push content in array   return $data;  } 

you can file array line-by-line file. if want each item in array array use array_map process lines:

$data = file($path_file); $data = array_map(function($l) { return explode(" ", $l); }, $data); 

if file's format not "values separated single space" code won't work correctly; in case use appropriate split function (perhaps preg_split) break each line tokens.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -