批改状态:合格
                        老师批语:
                    
                            <?php
//字符串查找并替换的两个函数
//str_replace()  substr_replace()
//1.str_replace()
$str = 'php is the best language in the world';
echo str_replace('php','java',$str),'<br>';
//删除式替换
echo str_replace('php','',$str),'<br>';
//一次性替换多个文件
echo str_replace(['php','the','world'],'html',$str),'<br>';
echo str_replace(['php','the','world'],['java','css','js'],$str),'<br>';
//str_replace()该函数是区分大小写的。请使用 str_ireplace() 函数执行不区分大小写的搜索。
//2. substr_replace()
echo substr_replace($str,'php 是世界上最好的语言',0),'<br>'; // 从头开始替换
echo substr_replace($str,'语言 ',16,0),'<br>'; // 从16开始
echo substr_replace($str,'语言 ',16,8),'<br>'; // 从16开始,往后再数8位
//删除式替换
echo substr_replace($str,'',16,8),'<br>'; // 从16开始,往后再数8位点击 "运行实例" 按钮查看在线实例
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号