源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP将字符串首字母大小写转换的实例

  • 时间:2022-04-05 06:35 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP将字符串首字母大小写转换的实例
[b]每个单词的首字母转换为大写:[/b][b]ucwords()[/b]
<?php 
$foo = 'hello world!'; 
$foo = ucwords($foo);       // Hello World! 
 
$bar = 'HELLO WORLD!'; 
$bar = ucwords($bar);       // HELLO WORLD! 
$bar = ucwords(strtolower($bar)); // Hello World! 
?> 
[b]第一个单词首字母变大写:[/b][b]ucfirst()[/b]
<?php 
$foo = 'hello world!'; 
$foo = ucfirst($foo);       // Hello world! 
 
$bar = 'HELLO WORLD!'; 
$bar = ucfirst($bar);       // HELLO WORLD! 
$bar = ucfirst(strtolower($bar)); // Hello world! 
?> 
[b]第一个单词首字母变小写:[/b][b]lcfirst()[/b]
<?php 
$foo = 'HelloWorld'; 
$foo = lcfirst($foo);       // helloWorld 
 
$bar = 'HELLO WORLD!'; 
$bar = lcfirst($bar);       // hELLO WORLD! 
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD! 
?> 
所有 字母变大写:[b]strtoupper()[/b] 所有 字母变小写:[b]strtolower() [/b] 以上这篇PHP将字符串首字母大小写转换的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部