需要转型
PROP_RESOURCE_TYPE至
propResourceType或
setPropResourceType_的数量和字符串长度不固定。
我不是很喜欢preg_replace,你能帮我吗?
发布于 2013-07-09 22:27:13
为了完整起见,下面是一个正则表达式如何提供帮助的示例:
// match each underscore followed by a letter
echo preg_replace_callback('/_([a-z])/', function($m) {
return strtoupper($m[1]); // upper case the letter
}, strtolower('PROP_RESOURCE_TYPE'));发布于 2013-07-09 22:21:29
lcfirst(implode(array_map('ucfirst', explode('_', strtolower($str)))));发布于 2013-07-09 22:21:47
一种可能的解决方案是:
<?php
$step1 = strtolower("PROP_RESOURCE_TYPE"); // prop_resource_type
$step2 = str_replace("_"," ",$step1); // prop resource type
$step3 = ucwords($step2); // Prop Resource Type
$step4 = str_replace(" ","",$step3); // PropResourceType
$step5 = "set".$step4;
?>https://stackoverflow.com/questions/17550534
复制相似问题