PHP extract data from text file and write to another file
<p>This is my first post on the internet for some assistance with coding so please bear with me!
I have been finding open code on the internet for a few years and modding it to do what I want but I seem to have come up against a wall with this one that I am sure is very simple. If you would please be able to help me it would be very much appreciated.</p>

<p>I have the following page:</p>

<pre><code>    &lt;?php 
    $text = $_REQUEST['message'];
    $f = file_get_contents("all.txt"); 
    $f = explode(", ", $f); 

    function modFile($pos, $tothis, $inthis)
    { 
        foreach($inthis as $pos =&gt; $a){ 
        } 
        $newarr = implode("\r\n", $inthis); 
        $fh = fopen("example.txt", "w"); 
        fwrite($fh, $newarr); 
        fclose($fh); 
    } 

    modFile(4, '', $f); 
</code></pre>

<p>I have a file (all.txt) with the following:</p>

<pre><code>    11111111111, 22222222222, 33333333333, 44444444444
</code></pre>

<p>That I wish to display like this:</p>

<pre><code>    11111111111 
    22222222222
    33333333333
    44444444444
</code></pre>

<p>and to add a space then some text after each number where the text is the same on each line:</p>

<pre><code>    11111111111 text here
    22222222222 text here
    33333333333 text here
    44444444444 text here
</code></pre>

<p>I have an html form that passes the custom text to be appended to each line.
I need to keep the file all.txt intact then save the newly formatted file with a different name.</p>

<p>I have tried putting variables into the implode where I currently have the "\r\n" but this does not work.</p>

<p>Any help very much appreciated.</p>

<p>Thanks in advance!</p>
