tags:

views:

55

answers:

1

Ok lets say I have a File called File.txt and it contains

Hello
World
!!!!!

Ok now I have it so they may Post something to add to the string But it has ot be right under the string "Hello". How would I go about doing that ?

+3  A: 
$mystring="string to append";
$file="file";
$data = file($file);
foreach ($data as $k=>$v){
    if ( strpos($v,"Hello") !==FALSE){
        $data[$k]=$data[$k] . "$mystring\n";
    }
}
file_put_contents($file,$data);
ghostdog74
+1 After reading the title again, I think you've nailed it.
Jonathan Sampson
I agree This is very good Thank you Very much! +1 Great example
H4cKL0rD