首页 > Web开发 > 详细

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

时间:2017-05-18 10:30:57      阅读:331      评论:0      收藏:0      [点我收藏+]

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

 代码如下:
<?php
$foo = ‘hello world!‘;
$foo = ucwords($foo);             // Hello World!

 

$bar = ‘HELLO WORLD!‘;
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>

 

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

 代码如下:
<?php
$foo = ‘hello world!‘;
$foo = ucfirst($foo);             // Hello world!

 

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

 

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

 代码如下:
<?php
$foo = ‘HelloWorld‘;
$foo = lcfirst($foo);             // helloWorld

 

$bar = ‘HELLO WORLD!‘;
$bar = lcfirst($bar);             // hELLO WORLD!
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!
?>

 

所有字母变大写:strtoupper()
所有字母变小写:strtolower()

  • 1 strtolower()       //将字符串转换为小写形式
  • 2 strtoupper()     //将字符串转换为大写形式
  • 3 ucfirst()           //将字符串的第一个字符转换为大写形式
  • 4 ucwords()       //将字符串中每一个单词的首字母转换为大写形式

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

原文:http://www.cnblogs.com/sunjinxiu/p/6871720.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!