失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > php 英文小写变大写 PHP英文字母大小写转换如何实现

php 英文小写变大写 PHP英文字母大小写转换如何实现

时间:2022-12-12 04:09:40

相关推荐

php 英文小写变大写 PHP英文字母大小写转换如何实现

这次给大家带来PHP英文字母大小写转换如何实现,PHP英文字母大小写转换实现的注意事项有哪些,下面就是实战案例,一起来看一下。

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

$foo = 'hello world!';

$foo = ucwords($foo); // Hello World!

$bar = 'HELLO WORLD!';

$bar = ucwords($bar); // HELLO WORLD!

$bar = ucwords(

strtolower

($bar)); // Hello World!

?>

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

$foo = 'hello world!';

$foo = ucfirst($foo); // Hello world!

$bar = 'HELLO WORLD!';

$bar = ucfirst($bar); // HELLO WORLD!

$bar = ucfirst(strtolower($bar)); // Hello world!

?>

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

$foo = 'HelloWorld';

$foo = lcfirst($foo); // helloWorld

$bar = 'HELLO WORLD!';

$bar = lcfirst($bar); // hELLO WORLD!

$bar = lcfirst(

strtoupper

($bar)); // hELLO WORLD!

?>

所有字母变大写:strtoupper()

所有字母变小写:strtolower()

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

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

如果觉得《php 英文小写变大写 PHP英文字母大小写转换如何实现》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。