I have a string that I need help converting to preg_replace_callback. Any help with an explanation would be helpful.
Thanks
preg_replace('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($match[1])));
I have a string that I need help converting to preg_replace_callback. Any help with an explanation would be helpful.
Thanks
preg_replace('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($match[1])));
Here is exact example from the manual with small change:
$string = preg_replace_callback(
'/(?<=^|[\x09\x20\x2D])./',
create_function(
// single quotes are essential here,
// or alternative escape all $ as \$
'$matches',
'return strtoupper($matches[0]);'
),
$string
);
or:
function myfunc($matches)
{
return strtoupper($matches[0]);
}
$string = preg_replace_callback("/(?<=^|[\x09\x20\x2D])./", "myfunc", $string);