Home  >  Article  >  Backend Development  >  preg_replace(): The /e modifier is deprecated, use preg_replace_callback

preg_replace(): The /e modifier is deprecated, use preg_replace_callback

WBOY
WBOYOriginal
2016-06-06 20:43:00920browse

以前项目里有个函数:

preg_replace("/([A-Z])/e", "'_' . strtolower('\\1')", $str)

升级完php之后,就一直报:

preg_replace(): The /e modifier is deprecated, use preg_replace_callback 

请问这个要怎么改?

回复内容:

以前项目里有个函数:

preg_replace("/([A-Z])/e", "'_' . strtolower('\\1')", $str)

升级完php之后,就一直报:

preg_replace(): The /e modifier is deprecated, use preg_replace_callback 

请问这个要怎么改?

preg_replace_callback('/([A-Z])/',
                      function ($matches) {
                        return '_' . strtolower($matches[0]);
                      },
                      $str)

提问前就没有想过看看文档吗?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn