Blogger Information
Blog 27
fans 0
comment 0
visits 17909
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
字符串查找,代替-8.27
Yyk.的博客
Original
639 people have browsed it

实例演示substr(),strstr(),strpos()函数

实例

<?php
header("Content-Type:text/html;charset=utf-8");
//子串查询函数三个
$str='My name is YYk.';
echo substr($str,3),'<br>';
echo substr($str,3,4),'<br>';

echo strstr($str,'n'),'<br>';//返回n之后的数据(包括n)
echo strstr($str,'n',true),'<br>';//返回n之前的数据(不包括n)

echo strpos($str,'is');//返回字符串第一次出现的位置


?>

运行实例 »

实例演示str_replace(), substr_replace(

实例

<?php
header("Content-Type:text/html;charset=utf-8");
$str='My name is YYK.';
echo str_replace('My','Your',$str),'<br>';//替换
echo str_replace('My','',$str),'<br>';//删除式替换

echo str_replace(['My','YYK'],['Your','Lq',],$str),'<br>';//一次性替换多个内容(数组形式)

//忽略大小写的替换  str_ireplace
echo substr_replace($str,'1.',0,0);
?>

运行实例 »

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

实例演示: usort()二维数组的排序

实例

<?php
header("Content-Type:text/html;charset=utf-8");


$num =[
	['name'=>'MIke','grade'=>90],
	['name'=>'Jcak','grade'=>75],
	['name'=>'Liee','grade'=>96],
];
usort($num,function($m,$n){
	return strcmp($m['grade'] , $n['grade']);
	
	
});
echo '<pre>';
echo var_export($num)

?>

运行实例 »

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

个人总结:

        sort()正排序;    rsort()逆排序;    usort()自定义排序

        str_repalce()子串代替        substr_replace()根据位置替换

        substr()查询指定位置字符    strstr()查询指定子串

Correction status:qualified

Teacher's comments:
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