For instance,
I need to be able to search "file.php" for something like:
case 'casename' : Name::function(); break;
and add an additional case below, or just delete that case.
Ive tried this code:
$search = "case 'casename' : Name::function(); break;";
$toBeAdded = "case 'newcasename' : Name::function(); break;";
$input = $search . $toBeAdded;
$file = file_get_contents(file.php);
$newfile = preg_replace($search,$input,$newfile);
file_put_contents(file.php,$newfile);
and a few variations using preg_match and such
Now the main road block i keep hitting is it doesn't error out, but it wont output anything to file.php. However, i know that the concept is working cause if i just use a search string with out ":" or ";" it works fine, even if $toBeAdded contains those characters. I've also tried using : and \; to treat them as literal characters... but same result.
With incorporating preg_match it will error and output that it was because of a : or ;
What i'm wondering is,
1. Am i totally backwards on how im attempting this?
2. is there a better (working) way to achieve what im attempting to do?
3. Is this even going to be possible?
Im open to any suggestions.
Thanks again for the help!