Blogger Information
Blog 18
fans 0
comment 0
visits 9922
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
常用的字符串函数2018年8月27日作业
吕小布的博客
Original
587 people have browsed it

实例

<?php
//usort()二维数组的排序
$arry = [
    ['name'=>'li', 'grade'=>100],
    ['name'=>'liu', 'grade'=>30],
    ['name'=>'wang', 'grade'=>80],
];

usort($arry,function($a,$b){
    return strcmp($a['grade'], $b['grade']);
});

echo var_export($arry),'<hr>';
//实例演示str_replace(), substr_replace()
$a='My english is very good';
echo substr($a,11,2),'<br>';//获取指定位置或区间内的字符串
echo strstr($a,'very'),'<br>';//查找字符串的首次出现
echo strstr($a,'very',true),'<br>';//查找字符串的首次出现
echo strpos($a,'is'),'<hr>';//查找字符串首次出现的位置

//str_replace()
echo str_replace('very','非常',$a),'<br>';
echo str_replace(['english','is','very'],['英语','是','非常'],$a),'<br>';
//substr_replace()
echo substr_replace($a,'我的英语非常好',0),'<br>';//整体替换
echo substr_replace($a,'非常',11,0),'<br>';//插入
echo substr_replace($a,'非常',11,2),'<br>';//替换is
echo substr_replace($a,'',11,2),'<br>';//删除替换

运行实例 »

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

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