« trim
ucwords »

ucfirst

(PHP 4, PHP 5, PHP 7, PHP 8)

ucfirst — 文字列の最初の文字を大文字にする

説明

function ucfirst(string $string): string

string の最初の文字が "a" (0x61) から "z" (0x7a) までの ASCII 文字の場合、 それを大文字にします。

パラメータ

string

入力文字列。

戻り値

変換後の文字列を返します。

変更履歴

バージョン 説明
8.2.0 ケース変換は、setlocale() で設定されたロケールに依存しなくなりました。 ASCII 文字のみが変換されます。

例

例1 ucfirst() の例

<?php
$foo = 'hello world!';
echo ucfirst($foo), PHP_EOL;             // Hello world!

$bar = 'HELLO WORLD!';
echo ucfirst($bar), PHP_EOL;             // HELLO WORLD!
echo ucfirst(strtolower($bar)), PHP_EOL; // Hello world!
?>

参考

  • lcfirst() - 文字列の最初の文字を小文字にする
  • strtolower() - 文字列を小文字にする
  • strtoupper() - 文字列を大文字にする
  • ucwords() - 文字列の各単語の最初の文字を大文字にする
  • mb_convert_case() - 文字列に対してケースフォールディングを行う

関連キーワード:
ucfirst   最初   大文字   world   ucwords   ケース   Hello   strtolower   小文字   trim   履歴   setlocale   ロケール   依存   hello   参考   lcfirst   strtoupper   単語   convert   case   フォールディング
関連する関数・ページ:
function.mb-ucfirst   function.ucwords   function.strtoupper   function.lcfirst   function.mb-lcfirst   function.strtolower