Home >Backend Development >PHP Tutorial >编码风格转换

编码风格转换

WBOY
WBOYOriginal
2016-06-23 13:55:27937browse

一种编码风格,MyScoreIphone
转换成另一种编码风格 my_score_iphone
应该怎样做,分别使用java和php实现

其中,php使用函数

请多指教!


回复讨论(解决方案)

<?php$funcname = 'MyScoreIphone';$newfuncname = change($funcname);echo $funcname.'<br>';echo $newfuncname;function change($str){    $newstr = preg_replace_callback('/[A-Z]{1}/', 'f', $str);    return substr($newstr, 1);}function f($str){    return '_'.strtolower($str[0]);}?>

我想到了使用正则preg_replace,
可是不知道第二个参数怎样使,
原来还有preg_replace_callback,
谢了

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