Blogger Information
Blog 17
fans 0
comment 0
visits 10690
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
常用字符串操作函数_2018-08-29_8:40上传
斯达融的博客
Original
601 people have browsed it

作业代码:

实例

<?php
echo "<h3>编程1: 实例演示substr(),strstr(),strpos()函数</h3><hr />";
$str="My name is staroom";
echo "<h4>substr()</h4>";
echo "<p>My name is staroom <br />取前两位:",substr($str,0,2),",取后7位:",substr($str,-7),",从第3开始,取4位:",substr($str,3,4),"</p>";
echo "<h4>strstr()</h4>";
echo "<p>
查询name是否存在,返回name及后面内容:",strstr($str,"name"),",返回前面内容:",strstr($str,"name",true),"
</p>";
echo "<h4>strpos()</h4>";
echo "<p>
查询star首次出现的位置:",strpos($str,"star"),"
</p><hr />";
echo "<h3>编程2: 实例演示str_replace(), substr_replace()</h3><hr />";
$strs="My name is staroom. Staroom is a chinese";
echo "<h4>str_replace() str_ireplace()</h4>";
echo $strs,"<br />";
echo "<p>
替换staroom:",str_replace("staroom","Yuxicheng",$strs),"<br />忽略大小写:",str_ireplace("staroom","Yucicheng",$strs),"
</p>";
echo "<h4>sustr_replace()</h4>";
echo "<p>
从第20位开始替换:",substr_replace($strs,"I come from Hubei,China.",20),"
</p><hr />";
echo "<h3>编程3: 实例演示: usort()二维数组的排序</h3><hr />";
echo "<pre>";
$array=[[ "name"=>"张三","steps"=>20122],["name"=>"李四","steps"=>10982],["name"=>"王五","steps"=>18902]];
echo "原始:",var_dump($array),"<br />";
usort($array,function($n,$m){
  return $m['steps']<$n['steps'];
});

echo "步数大小到大:<br />";
var_dump($array);
 ?>

运行实例 »

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


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