Blogger Information
Blog 20
fans 0
comment 0
visits 14717
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
str_replace(), substr_replace() 2018.8.27
李逍遥
Original
890 people have browsed it

实例

<?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位

运行实例 »

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


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