0

I can not fix this error:

$match[1] = preg_replace('/(?<=^|[a-z])./e', 'strtoupper("\0")', strtolower(trim($match[1])));

How to change it?

3
  • The error tells you exactly what to do. You are familiar with the PHP Manual, yes? Commented Nov 5, 2015 at 8:14
  • Yes, I tried: [php]$match[1] = preg_replace_callback('/(?<=^|[a-z])./', create_function('$x', 'strtoupper("\0"); return strtolower(trim($x[1]))'), $match[1]);[/php] Commented Nov 5, 2015 at 8:19
  • The create_function syntax is pretty redundant now - inline anonymous functions are much more natural - see the answer below. Commented Nov 5, 2015 at 9:21

1 Answer 1

5

You should read the manual. The e modifier is deprecated and will be removed in further versions. Just use preg_replace_callback (the message told you..)

$match[1] = preg_replace_callback('/(?<=^|[a-z])./', function($m) {
    return strtoupper($m[0]);
}, strtolower(trim($match[1])));
Sign up to request clarification or add additional context in comments.

1 Comment

I used your answer to answer my own question. I noticed you didn't get credit for it here, so if you're still active, post it on my question here and I'll mark your answer as correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.