3

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 ?

1
  • 1
    Like, always insert at line 2? Or always after the "hello"? Commented Feb 19, 2010 at 1:53

1 Answer 1

4
$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);
Sign up to request clarification or add additional context in comments.

1 Comment

I agree This is very good Thank you Very much! +1 Great example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.