php data from text file to multidimensional array doesnt work but no console errors -


i've written code read in data text file.
data looks this:

11:12:12:test titel 1
12:13:13:test titel 2
13:14:14:test titel 3

the following code reads date, splits 1 string each line, go in 1 array. works perfectly. after this, should devide each line again in string go in array, , these arrays go 1 multidimensional array. last part doesnt work... think it's strange instead of errors, of half page, shows empty page... also, i've tried putting of code in comment, , i've narrowed down bit. give guys commented code, comments should go away, , should work that! thanks!

 <?php  $filename = "data.txt";  $fp = fopen($filename, "r");  $content = fread($fp, filesize($filename));  $lines = explode("\n", $content);  $parts = null;  fclose($fp);  print_r($lines);  echo sizeof($lines);  ($i=0; $i < sizeof($lines)-1 ; $i++) {    //the minus 1 corrects empty line automatically added when saving data.txt file    //$tempparts[] = explode(":", $lines[i]);    //array_push($parts, $tempparts);  }  //echo "<br/>"  echo "all parts: "  //for ($row=0; $row < sizeof($lines)-1; $row++) {  //  ($col=0; $col < sizeof($parts[$row]); $col++) {  //echo $parts[$row][$col];  //  }  //}  ?>

i think preg_split want.

$filename = "data.txt"; $fp = fopen($filename, "r"); $content = fread($fp, filesize($filename));  //$content = "11:12:12:test titel 1             12:13:13:test titel 2             13:14:14:test titel 3";  $arr = preg_split("/(:|\n)/" ,$content);   var_dump($arr); 

see here: http://www.phpliveregex.com/p/hnh
click on preg_split on right side of screen make work

maybe works better you?

preg_match_all("/(\d+):(\d+):(\d+):(.*)/", $content, $arr); 

click preg_match_all:
http://www.phpliveregex.com/p/hnw


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -