Blogger Information
Blog 57
fans 0
comment 0
visits 46857
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
字符串查找并替换的二个函数
藍錄的博客
Original
779 people have browsed it

实例

<?php
/**
 * 字符串查找并替换的二个函数
 */

// str_replace(), substr_replace()
$str = 'Peter Zhu is PHP Lecture';
//1.str_replace()
echo str_replace('PHP', 'JAVA', $str), '<br>';
//删除式替换
echo str_replace('Zhu', '', $str), '<br>';
// 一次性替换多个内容
echo str_replace(['Peter','Zhu','PHP'],'朱老师', $str), '<br>';
echo str_replace(['Peter','Zhu','Lecture'],['彼得','朱','讲师'], $str), '<br>';
// str_ireplace(): 忽略大小写的替换
echo '<hr>';
// substr_replace()

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);

运行实例 »

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

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