Home >Backend Development >PHP Tutorial >preg_replace替换为preg_replace_callback

preg_replace替换为preg_replace_callback

WBOY
WBOYOriginal
2016-06-20 12:30:31908browse

preg_replace(array('/(^|_|-)+(.)/e', '/\.(.)/e'), array("strtoupper('\\2')", "'_'.strtoupper('\\1')"), $id); 
各位为大神,替换为preg_replace_callback怎么写啊


回复讨论(解决方案)

     $line  =  preg_replace_callback (         '|<p>\s*\w|' ,        function ( $matches ) {            return  strtoupper( $matches [ 0 ]) ..... ;   // 这个地方照葫芦画瓢,\\1 就是这里的 $matches [ 0 ]        },         $line     );


试试就知道了

$id = preg_replace_callback('/(^|_|-)+(.)/', function($m) { return strtoupper($m[2]); }, $id);$id = preg_replace_callback('/\.(.)/', function($m) { return '_' . strtoupper($m[1]); }, $id);echo $id;

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
Previous article:PHP 学习笔记Next article:数据库查询条件