Buenas,
En este enlace podrás ver como escribir en un fichero.
http://es2.php.net/manual/es/function.fwrite.php
Y en este podrás ver como se lee.
http://es2.php.net/manual/es/function.fwrite.php
Luego manipular el "$contenido" ya es cosa tuya :)
Un saludo.