0

重複の可能性:
最初の文字を大文字で表示するにはどうすればよいですか?
PHP は、文の最初の単語の最初の文字を大文字にします

文の最初の文字とピリオドの後の文字を大文字にしたい。誰でも方法を提案できますか?

例えば、

//I have the following in a language class.
"%s needs to identify areas of strength and 
weakness. %s sets goals for self-improvement."; 

// in a view
$contone=$this->lang->line($colstr);// e.g get the above string.
//$conttwo=substr($contone, 3);//skip "%s " but this doesnot work when there 
//are more than one %s
$conttwo=str_replace("%s ", "", $contone);// replace %s to none 
$contthree = ucfirst($conttwo); // this only uppercase the first one

次の出力が必要です。

Needs to identify areas of strength and 
weakness. Sets goals for self-improvement.
4

2 に答える 2

2

以下で試してみてください。

複数の文を含む文字列内のピリオド (ピリオド) の後にすべての文字を大文字にする関数を実行します。

    $string = ucfirst(strtolower($string));     

    $string = preg_replace_callback('/[.!?].*?\w/', create_function('$matches', 'return strtoupper($matches[0]);'),$string);

    echo $string;

必要な変更を行ってください。

于 2012-01-21T07:43:07.433 に答える