ucfirst

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

ucfirst将字符串的首字母转换为大写

说明

ucfirst(string $string): string

string 的首字符(如果首字符是 "a"(0x61)到 "z"(0x7a)范围内的 ASCII 字符)转换为大写字母,并返回这个字符串。

注意字母的定义取决于当前区域设定。例如,在默认的 “C” 区域,字符 umlaut-a(ä)将不会被转换。

参数

string

输入字符串。

返回值

返回结果字符串。

更新日志

版本 说明
8.2.0 大小写转换不在依赖于使用 setlocale() 设置的区域。只会转换 ASCII 字符。

范例

示例 #1 ucfirst() 范例

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

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

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top