很多站长朋友们都不太清楚php字母大写,今天小编就来给大家整理php字母大写,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php如何创建包含所有大写字母的数组 2、 PHP 中文转拼音并首字母大写 3、 php中把字符串首字母转大写方法? 4、 PHP中怎样将字符串每个单词的首字符转换成大写 5、 PHP里,怎么将数组里的字符串的字母转换为大写 php如何创建包含所有大写字母的数组新建一个php文件,命名为test.php,用于讲解php如何将数组中所有字母改为大写。
请点击输入图片描述
在test.php文件中,使用header()方法将页面的编码格式设置为utf-8。
请点击输入图片描述
在test.php文件中,定义一个changeAbc函数,使用strtoupper函数将传入的参数转换为大写字母,并使用return将参数返回。
请点击输入图片描述
在test.php文件中,创建一个小写字母数组,用于测试。
请点击输入图片描述
在test.php文件中,使用array_map函数使用函数changeAbc对数组进行转换大写字母处理,最后,使用print_r输出结果。
请点击输入图片描述
在浏览器打开test.php文件,查看结果。
请点击输入图片描述
PHP 中文转拼音并首字母大写<?php
function getfirstchar($s0){
$fchar = ord($s0{0});
if($fchar >= ord("A") and $fchar <= ord("z") )return strtoupper($s0{0});
$s1 = iconv("UTF-8","gb2312", $s0);
$s2 = iconv("gb2312","UTF-8", $s1);
if($s2 == $s0){$s = $s1;}else{$s = $s0;}
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
if($asc >= -20319 and $asc <= -20284) return "A";
if($asc >= -20283 and $asc <= -19776) return "B";
if($asc >= -19775 and $asc <= -19219) return "C";
if($asc >= -19218 and $asc <= -18711) return "D";
if($asc >= -18710 and $asc <= -18527) return "E";
if($asc >= -18526 and $asc <= -18240) return "F";
if($asc >= -18239 and $asc <= -17923) return "G";
if($asc >= -17922 and $asc <= -17418) return "H";
if($asc >= -17417 and $asc <= -16475) return "J";
if($asc >= -16474 and $asc <= -16213) return "K";
if($asc >= -16212 and $asc <= -15641) return "L";
if($asc >= -15640 and $asc <= -15166) return "M";
if($asc >= -15165 and $asc <= -14923) return "N";
if($asc >= -14922 and $asc <= -14915) return "O";
if($asc >= -14914 and $asc <= -14631) return "P";
if($asc >= -14630 and $asc <= -14150) return "Q";
if($asc >= -14149 and $asc <= -14091) return "R";
if($asc >= -14090 and $asc <= -13319) return "S";
if($asc >= -13318 and $asc <= -12839) return "T";
if($asc >= -12838 and $asc <= -12557) return "W";
if($asc >= -12556 and $asc <= -11848) return "X";
if($asc >= -11847 and $asc <= -11056) return "Y";
if($asc >= -11055 and $asc <= -10247) return "Z";
return null;
}
function make_semiangle($str){
$arr = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', 'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E', 'F' => 'F', 'G' => 'G', 'H' => 'H', 'I' => 'I', 'J' => 'J', 'K' => 'K', 'L' => 'L', 'M' => 'M', 'N' => 'N', 'O' => 'O', 'P' => 'P', 'Q' => 'Q', 'R' => 'R', 'S' => 'S', 'T' => 'T', 'U' => 'U', 'V' => 'V', 'W' => 'W', 'X' => 'X', 'Y' => 'Y', 'Z' => 'Z', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd', 'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i', 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n', 'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's', 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x', 'y' => 'y', 'z' => 'z', '(' => '(', ')' => ')', '〔' => '[', '〕' => ']', '【' => '[', '】' => ']', '〖' => '[', '〗' => ']', '“' => '"', '”' => '"', '‘' => '\'', '’' => '\'', '{' => '{', '}' => '}', '《' => '<', '》' => '>', '%' => '%', '+' => '+', '—' => '-', '-' => '-', '~' => '-', ':' => ':', '。' => '.', '、' => ',', ',' => ',', ';' => ';', '?' => '?', '!' => '!', '…' => '...', '‖' => '|', '|' => '|', '〃' => '"', '' => ' ');
return strtr($str, $arr);
}
function pinyin1($zh){
$zh = make_semiangle($zh);
$ret = "";
$s1 = iconv("UTF-8","gb2312", $zh);
$s2 = iconv("gb2312","UTF-8", $s1);
if($s2 == $zh){$zh = $s1;}
for($i = 0; $i < strlen($zh); $i++){
$s1 = substr($zh,$i,1);
$p = ord($s1);
if($p > 160){
$s2 = substr($zh,$i++,2);
$ret .= getfirstchar($s2);
}else{
$ret .= $s1;
}
}
return $ret;
}
//用法
echo pinyin1('中文获取首字母大写,‘支持’全角“的”转化!');
?>
数字跟英文的全角被百度自动转了,如果需要下载附件源码
php中把字符串首字母转大写方法?strtoupper
(PHP 4, PHP 5, PHP 7)
strtoupper — 将字符串转化为大写
说明
strtoupper ( string $string ) : string
将 string 中所有的字母字符转换为大写并返回。
注意 “字母” 与当前所在区域有关。例如,在默认的 “C” 区域,字符 umlaut-a(ä)就不会被转换。
参数
string
输入字符串。
返回值
返回转换后的大写字符串。
范例
Example #1 strtoupper() 范例
注释
Note: 此函数可安全用于二进制对象。
参见
strtolower() - 将字符串转化为小写
ucfirst() - 将字符串的首字母转换为大写
ucwords() - 将字符串中每个单词的首字母转换为大写
mb_strtoupper() - 使字符串大写
PHP中怎样将字符串每个单词的首字符转换成大写php中可以通过ucfirst函数将一个字符串中的第一个字母转换成大写,而ucwords函数可以将一个字符串中每个单词的首字母转换成大写
<?php
$string = "php string functions are easy to use.";
$sentence = ucfirst($string);
$title = ucwords($string);
print("$sentence\n");
print("$title\n");
print("\n");
?>
输出结果如下:
Php string functions are easy to use.
Php String Functions Are Easy To Use
PHP里,怎么将数组里的字符串的字母转换为大写array_walk 多维数组试试 array_walk_recursive
<?php
$a = array("aa","bb",'cc');
array_walk($a,function($v,$k){$v = strtoupper($v);});
print_r($a);
关于php字母大写的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php字母大写 php是大写还是小写的详细内容...