php 提供有函数 ucfirst echo ucfirst ('abcd');Abcd自己写要用正则
echo preg_replace('/\b[a-z]/e', 'strtoupper("$0")', 'abcd');
//或
echo preg_replace_callback('/\b[a-z]/', function($m) { return strtoupper($m[0]); }, 'abcd');
echo preg_replace('/\b[a-z]/e', 'strtoupper("$0")', 'abcd');
//或
echo preg_replace_callback('/\b[a-z]/', function($m) { return strtoupper($m[0]); }, 'abcd');
//$str_from = array ("a", "b", "c", "d", "i", "f");
//$str_to = array ("A", "B", "C", "D", "I", "F");
$first=strtoupper(substr($text,0,1));
$str=substr($text,1);
//$text = str_replace($str_from, $str_to, $text);
return $first.$str;
}
echo upper('abcd');Abcd
还有问题我不想转换strtoupper,
我想西里尔字母直接能不转换。function upper($text){
$str_from = array ("а", "ә", "б", "в", "г", "ғ", "д");
$str_to = array ("А", "Ә", "Б", "В", "Г", "Ғ", "Д");
$text = str_replace($str_from, $str_to, $text);
return $text;
echo upper(‘Дисьма’);