PHP7 - The /e modifier is no longer supported, use preg_replace_callback instead
本问题已经有最佳答案,请猛点这里访问。
有人可以帮助我解决这个错误吗?
Warning: preg_replace(): The /e modifier is no longer supported, use
preg_replace_callback instead
我的原始代码:
1 | $match[1] = preg_replace('/(?<=^|[\\x09\\x20\\x2D])./e', 'strtoupper("\\0")', strtolower(trim($match[1]))); |
所以我这样尝试:
1 2 3 4 5 6 7 | $match[1] = preg_replace_callback('/(?<=^|[\\x09\\x20\\x2D])./e', function ($matches) { foreach ($matches as $match) { return strtoupper($match); } }, strtolower(trim($match[1]))); |
但是我仍然遇到相同的错误:
Warning: preg_replace_callback(): The /e modifier is no longer
supported, use preg_replace_callback instead
错误消息告诉您删除新代码中包含的
1 2 3 4 | / (?<=^|[\\x09\\x20\\x2D]). / e ^ ^------Pattern-------^ ^ ^ ---- Modifiers | | -------Delimiters------- |
您需要删除修饰符,因此
顺便说一句,您没有从在新代码中使用
1 2 3 4 5 6 7 8 9 10 | $inputString = 'foobazbar'; $result = preg_replace_callback('/^foo(.*)bar$/', function ($matches) { // $matches[0]:"foobazbar" // $matches[1]:"baz" return"foo" . strtoupper($matches[1]) ."bar"; }, $inputString); //"fooBAZbar" var_dump($result); |