![]() |
Explode .txt file into multidimensional array.
Currently I have a file that looks something like this:
Code:
Awesomedude123 = 399,408 = September 16, 2012:Code:
Array |
<?php
$MyArray = array ( 1 => array ("Awesomedude123","399,408","September 16, 2012"), 2 => array("Username11", "1,914,144", "September 16, 2012"), 3 => array("EpicSurfer", "1,031,427", "September 16, 2012"), ); echo $MyArray[2][0]."<br />"; echo $MyArray[2][1]."<br />"; echo $MyArray[2][2]."<br />"; ?> |
If you're on Linux, or otherwise have access to the bash shell you can use the 'while read' loop functionality. PHP may have something similar. It reads a text file line by line and returns it to the caller. the caller can be another loop of any kind. You can separate the lines with the ' = ' and remove the trailing : to get each item.
|
There are a few ways to do this.
PHP Code:
Edit: I like dos' suggestion too. Reading line by line is actually better than pulling a full string or an array. Look into the use of fscanf instead, which saves the need for a file() and foreach() call. |
| All times are GMT +1. The time now is 01:13 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.