Reputation:
I have a fairly simple problem I just cannot seem to find a solution. I want to delete a line containing a certain string in all the files in a directory on my website. This string contains double quotes though. I have been trying to find a solution using backslashing but its does not work.
The string I want to replace is:session_register("c$key");
I'm using this php and unix code:
$command = "sed -i '/session_register(\"c$key\")/d;' ./*";
$output = shell_exec($command);
I want to delete this line because session_register is outdated. It does not do anything but does not give me an error. What is the problem or how should I backslash?
Thanks a lot!
Upvotes: 1
Views: 43
Reputation: 785856
You need to double escape $
as well since $
is special regex symbol means end of input. Also use single quote instead of double for your $command
string assignment.
Try this:
$command = 'sed -i.bak \'/session_register("c\\$key")/d;\' ./*';
$output = shell_exec($command);
Upvotes: 1