PHP Code Snippets

Rename string in file
David Carr

This function is used to rename all instances of a word in a file.

Pararms are as follows:
1) Path to the file
2) The name to rename
3) The new name to be used

function renameString($src, $stringToRename, $newName)
{
    $file = file_get_contents($src);
    $file = str_replace($stringToRename, $newName, $file);
    file_put_contents($src, $file);
}

 



Copyright © 2011 - 2017 created by David Carr Web Developer. All code MIT license. All rights reserved. Built using Simple MVC Framework