Home > Backend Development > PHP Tutorial > PHP 中 正则表达式转化小写上划线变量变驼峰式

PHP 中 正则表达式转化小写上划线变量变驼峰式

WBOY
Release: 2016-06-13 13:16:47
Original
831 people have browsed it

PHP 中 正则表达式转化小写下划线变量变驼峰式
$method = 'set'.preg_replace(
      "/(?:^|_)([a-z])/e",
             "strtoupper('\\1')",
             $f);


如 first_name -> setFirstName
   click_url -> setClickUrl

正则中的/e可以执行. 此特性在perl中也是存在的.

如果不可以执行那只能
a -> A
b -> B
...
z -> Z
不知道还有没有别的办法.

Related labels:
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