split a line into several array elements
<p>I just got help from some on this site and was able to let a user upload a text file, and have the in the upload process grab the file and programatically search for keywords I specify. The script then counts how many times the word is found and outputs the entire line that it was found in into an array.</p>

<p>So the example results returns this when using this code:</p>

<pre><code>$sceneINT = $sf-&gt;countKeyWord('INT', $file);
</code></pre>

<p>with my class looking like so:</p>

<pre><code>public static function countKeyWord($word, $file){
    if(!$word)
        return NULL;

    $contents = file_get_contents($file);

    #standardise those line endings
    $contents = str_replace(array("\r","\r\n","\n\r","\n"),"\n",$contents);
    $lines = explode("\n", $contents);

    #find your result
    $result = $line_num = array();
    foreach($lines as $line_num =&gt; $l)
        if(strpos($l, $word)) {
            $result[] = $l;
            $line_nums[] = $line_num;
        }

    echo "&lt;pre&gt;"; // I am echoing out the results for debugging purpuses
    print_r($result);
    echo "&lt;/pre&gt;";
    return count($result); //final result shown to the user will only be the count
}
</code></pre>

<p>The results from this look like this:</p>

<pre><code>Array
(
    [0] =&gt;   3     INT. MARTEY'S OFFICE - DAY                                      3
    [1] =&gt;   4     INT. RONNEY'S OFFICE - DAY                                      4
    [2] =&gt;   6     INT. - BREEZE'S APARTMENT - DAY                                 6
    [3] =&gt;   9     INT. - WAREHOUSE/SOUNDSTAGE - DAY                               9
    [4] =&gt;  11     INT. EXAM ROOM - DAY                                           11
    [5] =&gt;  12     INT. RAJA'S OFFICE - LATER                                     12
    [6] =&gt;  14     INT. RAJA'S OFFICE - LATER                                     14
    [7] =&gt;  15     INT. LARGE OPERATING ROOM - DAY                                15
    [8] =&gt;  16     INT. RAJA'S OFFICE - LATER                                     16
    [9] =&gt;  17     INT. OLIVER'S CAR - DAY                                        17
    [10] =&gt;  20     INT. - ROY THUNDER'S OFFICE - NIGHT                            20
    [11] =&gt;  22     A 2ND CLIP FROM "GOLDEN GATE GUNS"- INT. BASEMENT - DAY        22
    [12] =&gt;  27     INT. HOUSE WIFE #3'S HOUSE - LATER                             27
    [13] =&gt;  29     INT.  LIBRARY - DAY                                            29
    [14] =&gt;  31     INT.  COFFEE SHOP - NIGHT                                      31
    [15] =&gt;  32     INT. WAITING AREA - DAY                                        32
    [16] =&gt;  33     INT. CASTING OFFICE - DAY                                      33
    [17] =&gt;  34     INT. CASTING OFFICE - DAY                                      34
    [18] =&gt;  35     INT. WAITING AREA - DAY                                        35
    [19] =&gt;  36     INT. WAITING AREA - LATER                                      36
    [20] =&gt;  37     INT. MOTEL ROOM - DAY                                          37
    [21] =&gt;         INT. WAITING AREA - LATER
    [22] =&gt;  39     INT. WAITING AREA - DAY                                        39
    [23] =&gt;  42     INT. WAITING AREA - DAY                                        42
    [24] =&gt;  43     INT. CASTING OFFICE - DAY                                      43
    [25] =&gt;  44     INT. AUDITION ROOM - DAY                                       44
    [26] =&gt;         INT. AUDITION ROOM - DAY
    [27] =&gt;  45     INT. WAITING AREA - DAY                                        45
    [28] =&gt;  46     INT. CASTING OFFICE - DAY                                      46
    [29] =&gt;  47     INT. AUDITION ROOM - DAY                                       47
    [30] =&gt;  48     INT. CASTING OFFICE - DAY                                      48
    [31] =&gt;  49     INT. WAITING AREA - DAY                                        49
    [32] =&gt;  50     INT. AUDITION ROOM - DAY                                       50
    [33] =&gt;  51     INT. CASTING OFFICE - DAY                                      51
    [34] =&gt;  52     INT. WAITING AREA - DAY                                        52
    [35] =&gt;  53     INT. CASTING OFFICE - DAY                                      53
    [36] =&gt;  54     INT. BURGER JOINT  - NIGHT                                     54
)
</code></pre>

<p>I need to upload the results into a database;</p>

<p>Taking Array[0] for example I would need to prepare that line for the database to look like this</p>

<pre><code>scene: 3
int_ext: INT
scene_name:    MARTEY'S OFFICE
day_night:    DAY
</code></pre>

<p>All that will go into 1 row in the database, I don't know how to approach this. How can I take the result and split into what I need and then send it to the database so that ALL items found are stored when the user presses the SAVE button.</p>
