I've tried in different ways, replacing a excerpt of text with metacharacters with another text with metacharacters in PHP. I know, it seems very simple but i've tried many times but didn't get it.
pattern: $Sel = 'anyvalues';
replacement: $Sel = 'one other';
subject: <?php $Sel = 'anyvalues';
I deeply tried using addslashes() and preg_quote() methods in different orders but it doesn't work. I need it to be as represented instead of looking for any workarounds.
Each one of these values lie in different files, i.e., the pattern lies in one file, replacement in another one, and subject in another as well.
$pattern = file_get_contents(file with $Sel = 'anyvalues'; value); $replacement = file_get_contents(file with $Sel = 'one other' value); $subject = file_get_contents(file with <?php$Sel = 'anyvalues'; value ); $result = preg_replace($pattern, $replacement, $subject);