今天学习了字符串的一些函数;
代码:
实例
<?php $str="welcome to china"; echo substr($str,2),'<br>'; echo substr($str,3,6),'<br>'; echo substr($str,-4),'<br>'; echo '<hr>'; $str1="test@163.com"; echo strstr($str1,'@'),'<br>'; echo strstr($str1,'@',true),'<br>'; echo '<hr>'; echo strpos($str,"to");
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php $str='小明在学习php,小明在学习html,小明在学习css'; echo str_replace('php','java',$str),'<br>'; echo str_replace('在',' ',$str),'<br>'; echo str_replace(['php','html','css'],'java',$str),'<br>'; echo str_replace(['php','html','css'],['java','mysql','thinkphp'],$str),'<br>';
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php $st=[ ['name'=>'jim','grade'=>97], ['name'=>'tom','grade'=>47], ['name'=>'lily','grade'=>67], ['name'=>'Lucy','grade'=>84], ]; usort($st,function ($m,$n){ return strcmp($m['grade'],$n['grade']); }); echo var_export($st,true);
运行实例 »
点击 "运行实例" 按钮查看在线实例