We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

fris on 03/09/08


Tagged

file replace strings


Versions (?)


replace a string in a file


Published in: PHP 


  1. <?
  2. $str=implode("\n",file('somefile.txt'));
  3. $fp=fopen('somefile.txt','w');
  4. $str=str_replace('oldkeyword','newkeyword',$str);
  5. fwrite($fp,$str,strlen($str));
  6. ?>

Report this snippet 

You need to login to post a comment.