PHP英文字母大小写转换函数

WBOY
Libérer: 2016-07-25 09:13:10
original
956 Les gens l'ont consulté

例1,每个单词的首字母转换为大写:ucwords()

  1. $foo = 'hello world!';
  2. $foo = ucwords($foo); // Hello World!
  3. $bar = 'HELLO WORLD!';
  4. $bar = ucwords($bar); // HELLO WORLD!
  5. $bar = ucwords(strtolower($bar)); // Hello World!
  6. ?>
复制代码

例2,第一个单词首字母变大写:ucfirst()

  1. $foo = 'hello world!';
  2. $foo = ucfirst($foo); // Hello world!
  3. $bar = 'HELLO WORLD!';
  4. $bar = ucfirst($bar); // HELLO WORLD!
  5. $bar = ucfirst(strtolower($bar)); // Hello world!
  6. ?>
复制代码

例3,第一个单词首字母变小写:lcfirst()

  1. $foo = 'HelloWorld';
  2. $foo = lcfirst($foo); // helloWorld
  3. $bar = 'HELLO WORLD!';
  4. $bar = lcfirst($bar); // hELLO WORLD!
  5. $bar = lcfirst(strtoupper($bar)); // hELLO WORLD!
  6. ?>
  7. 所有字母变大写:strtoupper()
  8. 所有字母变小写:strtolower()
复制代码

以上共介绍了五个英文字母大小写转换函数的函数,分别为ucwords、ucfirst、lcfirst、strtoupper、strtolower,各有所用。



Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!