Blogger Information
Blog 7
fans 0
comment 0
visits 4697
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
字符串函数--0418
李昊文叔叔的博客
Original
604 people have browsed it
实例
<?php 
header("Content-type: text/html; charset=utf-8"); 
echo  '<h3 align="center">字符串型函数</h3>';
echo  "<hr>";
//长度计算
//函数 mb_internal_encoding()获取内部字符的编码集  
$mb = mb_internal_encoding();
echo $mb.'<br>';
//1.strlen(变量) 获取一个字节型表示的字符串变量的长度
$name='李昊文叔叔666';
echo strlen($name);
// utf-8编码中 一个中文占3个字符; 5*3+3=18
echo '<br>'; 
//2.mb_strlen(变量,【编码类型 可选】) 获取字符串变量的长度
echo mb_strlen($name,$mb);
//编码类型默认utf-8  5+3=8
echo '<hr color="red">';

//字符串比较运算
//1.strcmp(变量1,变量2)比较2个数的大小  若A大于B 则输出1 若A等于B 则输出0  若A小于B 则输出-1
$a='hellokdlashld';
$b='hello';
echo strcmp($b, $a).'<br>';
echo strcmp($a, $b) == 0 ?'A大':'B大';
echo '<hr>';
//2.strncmp(变量1,变量2,比较的长度)比较2个变量从头开始部分长度是否相等 判断同上;
echo strncmp($a, $b,5).'<br>';
echo strncmp($a, $b,5) == 0 ?'相等':'不相等';
echo '<hr>';
//3.strcasecmp(变量1,变量2,比较的长度) 不区分




运行实例 »
点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post