Php/docs/function.ucwords

提供:Dev Guides
< Php
移動先:案内検索

ucwords

(PHP 4, PHP 5, PHP 7)

ucwords文字列の各単語の最初の文字を大文字にする


説明

ucwords ( string $string [, string $separators = " \t\r\n\f\v" ] ) : string

文字がアルファベットの場合、string の各単語の最初の文字を大文字にしたものを返します。

単語の定義は、separators で指定した任意の文字 (デフォルトはスペース、フォームフィード、改行、キャリッジリターン、 水平タブ、垂直タブ) の直後にある、あらゆる文字からなる文字列です。


パラメータ

string
入力文字列。
separators
オプションの separators で、単語の区切り文字を指定します。


返り値

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


例1 ucwords() の例

<?php$foo = 'hello world!';$foo = ucwords($foo);             // Hello World!$bar = 'HELLO WORLD!';$bar = ucwords($bar);             // HELLO WORLD!$bar = ucwords(strtolower($bar)); // Hello World!?>

例2 ucwords() で、区切り文字を指定する例

<?php$foo = 'hello|world!';$bar = ucwords($foo);             // Hello|world!$baz = ucwords($foo, "|");        // Hello|World!?>

例3 ucwords() で、追加の区切り文字を指定する例

<?php$foo = "mike o'hara";$bar = ucwords($foo);                 // Mike O'hara$baz = ucwords($foo, " \t\r\n\f\v'"); // Mike O'Hara?>

注意

注意: この関数はロケールを認識し、入力を現在設定されているロケールに従って処理します。しかしながら、この入力の処理はシングルバイトの文字セットでのみ動作します。マルチバイト文字(大半の西ヨーロッパ言語以外のそれが該当します)を扱う必要がある場合、mbstringintl 拡張モジュールを調べてみて下さい。

注意:

この関数はバイナリデータに対応しています。

参考