Basically what I want to do is a find and replace operation, so I retrieve the contents of a file and replace .quote with nothing, my current code: <?php function comment_code(){ $css = "test.css"; chmod($css, 0777); $handle = fopen($css, 'w'); $style = file_get_contents($css); $newstyle = str_replace(".quote", "nothing1", $style); fwrite($handle,$newstyle); echo $newstyle; }; comment_code(); ?> PHP: All thats doing is wiping the file. It also wipes the file if I use this: <?php function comment_code(){ $css = "test.css"; chmod($css, 0777); $handle = fopen($css, 'w'); $style = file_get_contents($css); echo $style; }; comment_code(); ?> PHP: Could someone please help, BP
You are calling it in wrong order. Do first $style = file_get_contents($css); and after that $handle = fopen($css, 'w');