2013-05-30 25 views
1

你好,我有一个项目,我需要cApitalize只在句子中的第二个字母。我现在PHP有strtoupper()和字符串strtoupper(字符串$字符串)ucfirst()返回第一个字母php在句子中大写第二个字母最少10个字符

因此,这里是我的最好的尝试

<?php 

$str = "capitalize"; 

$str = ucfirst(strtolower($str)); // makes all the letters lower case 
?> 

这是我感到困惑,如果0 =第一信和1 = 2次,然后我能不能做一个array(")count_chars()然后$val

+0

您可以从该字符串使用例如个人信第二个字母为'$ str [1]',将其大写,然后放回字符串中。 – doppelgreener

回答

0

我有一个想法来执行此操作.. 例如

$strmain='capitalize'; 
$result = substr($strmain, 0, 1); //result is c 
$result1=str_replace($result,'',$strmain);//now your result1 is apitalize 
$result2=ucfirst($result1); //now result2 is Apitalize 

$finalresult=$result.$result2 ///now your finalresult is cApitalize 
+0

不能正常工作。用“鳄鱼”,它返回“cRoodile”。 –

2

它的一个老问题,只是遇到了这个问题,所以会根据@doppelgreener评论提供答案。

这应该工作:

$str = "capitalize"; 
$str[1]= strtoupper($str[1]); 
echo $str; // cApitalize 
相关问题