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

preg_replace替换为preg_replace_callback

WBOY
Release: 2016-06-20 12:30:31
Original
885 people have browsed it

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     );
Copy after login


试试就知道了

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template