Help with PHP: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

When I upgrade PHP on my webserver from version 5.4 to 5.6, I get:
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home3/thenelson/public_html/barnwellmd/secure/Services/Twilio/Resource.php on line 90

Here is the code around line 90:
     * Return camelized version of a word
     * Examples: sms_messages => SMSMessages, calls => Calls, 
     * incoming_phone_numbers => IncomingPhoneNumbers
     * @param string $word The word to camelize
     * @return string
    public static function camelize($word) {
        return preg_replace('/(^|_)([a-z])/e', 'strtoupper("\\2")', $word);

Open in new window

I went online and read about the /e modifier and preg_replace_callback and I am a bit lost. What does the /e modifier do? Can I just remove the /e modifier from preg_replace? Can I change preg_replace to preg_replace_callback, remove the /e modifier or do I need to do more?

LVL 39
Who is Participating?
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.

Zakaria AcharkiAnalyst DeveloperCommented:
Hi @thenelson,

The e modifier is a deprecated regex modifier which allows you to use PHP code within your regular expression. This means that whatever you parse in will be evaluated as a part of your program. It was deprecated for security reasons, take a look at :

Anyway, your function body could be replaced by :

return  str_replace('_', '', ucwords($word, "_"));

Open in new window

The use of ucwords will uppercase the first character of each word in your string then str_replace function will replace all occurrences of the underscores '_' in your string $word.

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
thenelsonAuthor Commented:
Quite strange: I changed the code to:
    public static function camelize($word) {
        //return preg_replace('/(^|_)([a-z])/e', 'strtoupper("\\2")', $word);
		return  str_replace('_', '', ucwords($word, "_"));

Open in new window

and uploaded the new Resource.php to my webserver but when I upgrade my PHP to version 5.6, I still get the exact same message.

None of the PHP scripts I have on my webserver reference Resource.php so I am guessing the code in Resource.php is being called by which is processing some of the code.  I sent an email asking them about that.

Thanks for your help. I'll let you know what I find out.
Zakaria AcharkiAnalyst DeveloperCommented:
You're welcome, Yes that strange make sure all goes right from your side and we hope they will answer quickly.
thenelsonAuthor Commented:
The problem preg_replace() code runs off the website. Twilio has upgraded code. I am communicating with them to switch to it.

Thanks for your input.
Zakaria AcharkiAnalyst DeveloperCommented:
You're welcome, glad to help.
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.