preg_replace_callback $1 expression error

Hello, I'm trying to replace a deprecated preg_replace function with a preg_replace_callback and I'm running into a bit of a roadblock with the placement of some of the regex

$str = preg_replace("/\\b($all_uppercase)\\b/e", 'mb_strtoupper("$1", CHARSET)', $str);

Open in new window

Updated (but wrong):
$str = preg_replace_callback("/\\b($all_uppercase)\\b", create_function ( '$matches', 'return mb_strtoupper(matches[$1], CHARSET);'), $str);

Open in new window

I think I understand everything but I'm not sure how to represent the $1 in the new anonymous function with the matches[] variable.  Can someone tell me what the proper syntax for this translation is?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Any particular reason you can't just do this
$str = preg_replace_callback("/\\b($all_uppercase)\\b", function($matches) {
	return mb_strtoupper(matches[1], CHARSET);
}, $str);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FourMatAuthor Commented:
I think maybe I should clarify the problem:  It appears that the function is working, but it is kicking back the following warnings:

PHP Warning:  preg_replace_callback(): Requires argument 2, '', to be a valid callback in /home/XXX/filename on line 36
PHP Parse error:  syntax error, unexpected '[' in /home/XXX/filename(36) : runtime-created function on line 1

Both [$1] and [1] seem to return the same result.  The function produce the proper result, but it's kicking back the warnings.
Julian HansenCommented:
Are you getting the warnings with the anonymous function suggestion I posted as well?

Can you establish if the code I posted does what you want - we can work backwards from there.
FourMatAuthor Commented:
I was able to get that to work after I made a few changes.  I was missing a / delimiter in the regex, and I needed to add a $ to denote a variable on the matches[1] for the mb_strtoupper function

$str = preg_replace_callback("/\\b($all_uppercase)\\b/", function($matches) {
	return mb_strtoupper($matches[1], CHARSET);
}, $str);

Open in new window

Thanks for the help!
Julian HansenCommented:
Glad you got it working.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.