Note that there are some explanatory texts on larger screens.

plurals
  1. POExplode contents of a txt file into array
    primarykey
    data
    text
    <p>I´m having trouble exploding contents of a .txt file (structure below):</p> <pre><code> 01Name 1 02whatever contents 03whatever contents ------------------- 01Name 2 02whatever contents 03whatever contents </code></pre> <p>As you can see, the "delimiter" is "-------------------". Now, the question is: how to explode this file into an array, so I can search for a specific name and display that block´s contents? I´ve tried to explode like this:</p> <pre><code> header("Content-type:text/plain"); $file = fopen("cc/cc.txt", "r"); while (!feof($file)) { $lot = fgets($file); $chunk = explode("-------------------",$lot); print_r($chunk); } fclose($file); </code></pre> <p>And got this as a result:</p> <pre><code> Array ( [0] =&gt; 01Name 1 ) Array ( [0] =&gt; 02whatever contents ) Array ( [0] =&gt; 03whatever contents ) Array ( [0] =&gt; ------------------- ) Array ( [0] =&gt; 01Name 2 ) Array ( [0] =&gt; 02whatever contents ) Array ( [0] =&gt; 03whatever contents ) </code></pre> <p>when i wanted to get this as a result:</p> <pre><code> Array ( [0] =&gt; 01Name 1 [1] =&gt; 02whatever contents [2] =&gt; 03whatever contents ) Array ( [0] =&gt; 01Name 2 [1] =&gt; 02whatever contents [2] =&gt; 03whatever contents ) </code></pre> <p>I´ve searched <a href="https://stackoverflow.com/questions/8479672/php-assigning-fgets-output-to-an-array">PHP; assigning fgets() output to an array</a> and <a href="https://stackoverflow.com/questions/6159683/read-each-line-of-txt-file-to-new-array-element">Read each line of txt file to new array element</a> , with no luck.</p> <p>Any thoughts?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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