Home >Backend Development >PHP Tutorial >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:001030browse

以前项目里有个函数:

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

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

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

请问这个要怎么改?

回复内容:

以前项目里有个函数:

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

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

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

请问这个要怎么改?

<code class="lang-php">preg_replace_callback('/([A-Z])/',
                      function ($matches) {
                        return '_' . strtolower($matches[0]);
                      },
                      $str)
</code>

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

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