note 51565 added to function.str-replace

From: Date: Mon, 04 Apr 2005 14:00:16 +0000
Subject: note 51565 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-87428@lists.php.net to get a copy of this message
I wrote 2 function's file_replace() and dir_replace() with str_replace() signature function file_replace ($search, $replace, $filename) { if (file_exists($filename)) { $cnt = file_get_contents($filename); if (strstr($cnt, $search)) { $cnt = str_replace($search, $replace, $cnt); return file_put_contents($filename, $cnt); } return true; } return false; } function dir_replace ($search, $replace, $dirname, $recursive = true) { $dir = opendir($dirname); while ($file = readdir($dir)) { if ($file != '.' && $file != '..') { if (is_dir($dirname.'/'.$file)) { if ($recursive) { dir_replace($search, $replace, $dirname.'/'.$file); } } else { file_replace($search, $replace, $dirname.'/'.$file); } } } } usage ('search', 'replace', '/usr/home/root'); ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51565 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51565&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51565&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51565&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51565&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51565&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51565&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87428) next »