<?php
/**
* 字符串的大小写转换
*/
// strtolower()
echo strtolower('THIS IS A PHP COURSE'), '<br>';
// strtoupper()
echo strtoupper('this is a php course'), '<br>';
// ucfirst()
echo ucfirst('this is a php course'), '<br>';
// ucwords()
echo ucwords('this is a php course'), '<br>';
// 应用1: 将文件统一转为小写,实现跨平台(Linux是区分大小写)
echo '<pre>';
$files = ['Model.php','Action.php', 'CreatUser.php'];
foreach ($files as $file) {
$res[] = strtolower($file);
}
$files = $res;
echo var_export($files, true), '<br>';
// 应用2.将要进行判断的字符串转为统一的格式
$opt = 'EDIT';
switch (strtolower($opt))
{
case 'select':
print '查询操作'; break;
case 'edit':
print '编辑操作'; break;
case 'delete':
print '删除操作'; break;
case 'update':
print '更新操作'; break;
default:
print '非法操作'; break;
}点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号