$val) { // check that the value can be casted to string // 値を文字列にキャストできることを確認する if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) { $replace['{' . $key . '}'] = $val; } } // interpolate replacement values into the message and return // 置換値をメッセージに挿入して返す return strtr($message, $replace); } // a message with brace-delimited placeholder names // 中括弧で区切られたプレースホルダー名を含むメッセージ $message = "User {username} created"; // a context array of placeholder names => replacement values // コンテキスト配列(プレースホルダー名=>置換値) $context = array('username' => 'bolivar'); // echoes "User bolivar created" // "User bolivar created" をエコーする echo interpolate($message, $context);