实例
<?php /** * 编程1: 实例演示substr(),strstr(),strpos()函数 */ $str = 'I am very happy to learn from teacher zhu on PHP Chinese website'; echo substr($str,10),'<br>'; echo substr($str,10,5),'<br>'; echo substr($str,-7,3),'<hr>'; $mail = 'root@hcses.com'; echo strstr($mail,"@"),'<br>'; echo strstr($mail,"@",true),'<hr>'; echo strpos($str, 'learn');
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php /** * 编程2: 实例演示str_replace(), substr_replace() */ $str = 'Peter Zhu is PHP Lecture'; echo str_replace('PHP', 'JAVA', $str), '<br>'; echo str_replace(['Peter','Zhu','PHP'],'朱老师', $str), '<br>'; echo str_replace(['Peter','Zhu','Lecture'],['彼得','朱','讲师'], $str), '<br>'; echo '<hr>'; echo substr_replace($str,'PHP是最好的编程语言',0), '<br>'; echo substr_replace($str,'PHP是最好的编程语言',0,strlen($str)), '<br>'; echo substr_replace($str, 'PHP中文网 ',13,0),'<br>'; echo substr_replace($str, 'JAVA',13,3),'<br>'; // 删除式替换 echo substr_replace($str, '',6,3);
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php /** * 编程3: 实例演示: usort()二维数组的排序 */ $stu = [ ['name'=>'林心如','grade'=>98], ['name'=>'范冰冰','grade'=>55], ['name'=>'左小青','grade'=>73], ]; echo '排序之前:',var_export($stu,true),'<hr>'; //用户自定义排序规则 usort($stu, function ($m, $n) { //$m ,$n实际上还是一个数组 return strcmp($m['grade'], $n['grade']); }); echo '排序之后:',var_export($stu,true),'<hr>';
运行实例 »
点击 "运行实例" 按钮查看在线实例