PHP strtr()関数
例
文字列内の文字「ia」を「eo」に置き換えます。
<?php
echo strtr("Hilla Warld","ia","eo");
?>
定義と使用法
strtr()関数は、文字列内の特定の文字を変換します。
注: fromパラメーターとtoパラメーターの長さが異なる場合は、両方とも最短の長さにフォーマットされます。
構文
strtr(string,from,to)
また
strtr(string,array)
パラメータ値
Parameter | Description |
---|---|
string | Required. Specifies the string to translate |
from | Required (unless array is used). Specifies what characters to change |
to | Required (unless array is used). Specifies what characters to change into |
array | Required (unless to and from is used). An array containing what to change from as key, and what to change to as value |
技術的な詳細
戻り値: | 翻訳された文字列を返します。配列パラメータに空の文字列( "")であるキーが含まれている場合、FALSEを返します 。 |
---|---|
PHPバージョン: | 4歳以上 |
その他の例
例
文字列「Helloworld」を「Hiearth」に置き換えます。
<?php
$arr = array("Hello" => "Hi", "world" => "earth");
echo strtr("Hello world",$arr);
?>
❮PHP文字列リファレンス