Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This code (using a <code>for</code> loop):</p> <pre><code>&lt;?php $data[] = "/home/user/data/section1/dir1/20120107/filename.txt:random text after the colon"; $data[] = "/home/user/data/section1/dir1/20120108/filename.txt: More random text after the colon"; $data[] = "/home/user/data/section1/dir2/20120107/filename.txt: More random text after the colon"; $data[] = "/home/user/data/section1/dir2/20120108/filename.txt: More random text after the colon"; $data[] = "/home/user/data/section1/dir3/20120107/filename.txt: More random text after the colon"; $data[] = "/home/user/data/section1/dir3/20120106/filename.txt: More random text after the colon"; $data[] = "/home/user/data/section1/dir3/20120108/filename.txt: More random text after the colon"; for($i = 0; $i &lt; count($data); $i++) { $data[$i] = str_replace('/home/user/data/section1/','',$data[$i]); $tmp = explode('/', $data[$i]); $newData[$i] = array( 'dir' =&gt; $tmp[0], 'date' =&gt; $tmp[1] ); $tmp = explode(':', $tmp[2]); $newData[$i]['fileName'] = $tmp[0]; $newData[$i]['text'] = $tmp[1]; } print_r($newData); ?&gt; </code></pre> <p>Or this code (using a <code>foreach</code> loop):</p> <pre><code>&lt;?php $data[] = "/home/user/data/section1/dir1/20120107/filename.txt:random text after the colon"; $data[] = "/home/user/data/section1/dir1/20120108/filename.txt: More random text after the colon"; $data[] = "/home/user/data/section1/dir2/20120107/filename.txt: More random text after the colon"; $data[] = "/home/user/data/section1/dir2/20120108/filename.txt: More random text after the colon"; $data[] = "/home/user/data/section1/dir3/20120107/filename.txt: More random text after the colon"; $data[] = "/home/user/data/section1/dir3/20120106/filename.txt: More random text after the colon"; $data[] = "/home/user/data/section1/dir3/20120108/filename.txt: More random text after the colon"; foreach($data as $d) { $tmp = explode('/', str_replace('/home/user/data/section1/','',$d)); $tmp2 = explode(':', $tmp[2]); $newData[] = array( 'dir' =&gt; $tmp[0], 'date' =&gt; $tmp[1], 'filename' =&gt; $tmp2[0], 'text' =&gt; $tmp2[1] ); } print_r($newData); ?&gt; </code></pre> <p>Outputs:</p> <pre><code>Array ( [0] =&gt; Array ( [dir] =&gt; dir1 [date] =&gt; 20120107 [fileName] =&gt; filename.txt [text] =&gt; random text after the colon ) [1] =&gt; Array ( [dir] =&gt; dir1 [date] =&gt; 20120108 [fileName] =&gt; filename.txt [text] =&gt; More random text after the colon ) ============ more data here ============ [6] =&gt; Array ( [dir] =&gt; dir3 [date] =&gt; 20120108 [fileName] =&gt; filename.txt [text] =&gt; More random text after the colon ) ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload