如何在PHP中创建第一个Char Upper?

str*_*ade 3 php string

我需要知道我可以做一个字符串喜欢"hello""Hello"使用PHP?我只需要第一个角色为Upper

Liz*_*ard 10

使用该功能ucwords(); 这将完成字符串中的每个单词,使用ucfirst()将只做第一个单词.

echo ucwords('hello my name is jim');

// Hello My Name Is Jim

echo ucfirst('hello my name is jim');

// Hello my name is jim
Run Code Online (Sandbox Code Playgroud)


cod*_*ict 5

你需要这个ucfirst功能.

如果该字符是字母,则返回str大写的第一个字符的字符串.

它不会使其他字符小写.为确保只有第一个字母为大写,其余全部为小写,您可以执行以下操作:

ucfirst(strtolower($str))
Run Code Online (Sandbox Code Playgroud)