Preg_replace_callback function $ val & nbsp; preg_replace ([[^ [] *)] eis, & nbsp ;.. str_replace ($, $, \ 1), & nbsp; $ val); how to rewrite this sentence with the preg_replace_callback function & nbsp;
$val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);
How can I rewrite this sentence using the preg_replace_callback function?
------ Solution --------------------
$val = preg_replace_callback("/\[([^\[\]]*)\]/eis", function($match){ return str_replace('$','\$',$match)}, $val);
------ Solution --------------------
$val = preg_replace_callback(
'/\[([^\[\]]*)\]/is',
function ($matches) {
return '.'.str_replace('$','\$',$matches[1]);
},
$val
);
echo $val;
------ Solution --------------------
Reference:
The last line is the code include in the middle. I don't know how to change it.
$pattern = '/
.*?
/s';
$replacement = "'{include file='.strtolower('\\1'). '}'";
$source = preg_replace_callback($pattern, $replacement, $source);
--
The same is still a string, or the original method.
------ Solution --------------------
$ Replacement = function ($ matches) {return '{include file ='. strtolower ($ matches [1]). '}';};