The backslash is an escape character, it's used to escape the proceeding backslash. What that means is that it translates \\1
to \1
, and \1
is a reference to the output of the preg_replace. Your code had some errors, I cleaned it up:
function cc($re,$val){
return preg_replace( '/('.$re.')/ei' ,'strtolower("\\1")',$val);
}
Keep in mind that this won't work in newer versions of PHP, because in newer versions of PHP, the /e modifier is no longer supported, and we're encouraged to use preg_replace_callback() instead, like so:
function cc($re,$val){
return preg_replace_callback( '/('.$re.')/i' ,function($matches){
return strtolower($matches[1]);
},$val);
}