I have the following piece of code: http://pastebin.com/VaZkRxSu. And I am trying to update the functions preg_replace
with preg_replace_callback
. I don't understand what would be the callback
in my case.
A callback that will be called and passed an array of matched elements in the subject string. The callback should return the replacement string. This is the callback signature:
string handler ( array $matches )
- This is what it says on php.net.
Issue is located on following lines:
Line 160
$file_contents = preg_replace("!{$ldq}\*.*?\*{$rdq}!se","",$file_contents);
In this case preg_replace replacement is an empty field ""
. I have tried just changing the preg_replace to preg_replace_callback, but I get error: (2) preg_replace_callback(): Requires argument 2, '', to be a valid callback
.
Line 163
$file_contents = preg_replace('%(<\?(?!php|=|$))%i', '<?php echo \'\\1\'?>'."\n", $file_contents);
Line 168
$file_contents = preg_replace("!{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}!s", stripslashes($ldq . "literal" . $rdq), $file_contents);
Line 173
$file_contents = preg_replace("!{$ldq}\s*php\s*{$rdq}(.*?){$ldq}\s*/php\s*{$rdq}!s", stripslashes($ldq . "php" . $rdq), $file_contents);
Line 196
$text[$i+1] = preg_replace('~^(\r\n|\r|\n)~', '', $text[$i+1]);
Line 208
$compiled_text = preg_replace('!\?>\n?<\?php!', '', $compiled_text);
I also tried adding as the callback a function($m) like here
Please help me on this, I am a noob and doing my best on learning php.