str-replace的认识-读fleaphp写
来源:互联网 发布:优盘格式化数据恢复 编辑:程序博客网 时间:2024/06/06 14:01
fleaphp中根据类的命名可以loadClass($className)装载class,在其中str-replace起了相当大的作用,不过对str-replace 的认识还不是很深,惭愧~ 于是在copy了写东东贴在下面,以后上博可复习复习。
格式: [@str_replace("要替换的旧内容", "要取代原内容的新字符", $被替换内容的变量名)] [@str_replace(array('旧1','旧2','旧3'), array('新1','新2','新3'), $被替换内容的变量名)] [@str_replace(array('旧1','旧2','旧3'), '新内容', $被替换内容的变量名)] 实例: 多对一替换:想把内容字段里所有的<p></p>标签清除掉,替换成空 [@str_replace(array('<p>','</p>'), '', $Content)] 一对一替换:想把内容字段里所有的<br>标签换成<p>
[@str_replace('<br>', '<p>', $Content)] 多对多替换:想把内容字段里的<br>换成<br />, 同时<p>换<hr>,把</p>全清除
[@str_replace(array('<br>', '<p>','</p>'), array('<br />','<hr>',''), $Content)]
<?php // Provides: <body text='black'> $bodytag = str_replace("%body%", "black", "<body text='%body%'>"); echo $bodytag; // Provides: Hll Wrld f PHP $vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U"); $onlyconsonants = str_replace($vowels, "", "Hello World of PHP"); echo $onlyconsonants; // Provides: You should eat pizza, beer, and ice cream every day $phrase = "You should eat fruits, vegetables, and fiber every day."; $healthy = array("fruits", "vegetables", "fiber"); $yummy = array("pizza", "beer", "ice cream"); $newphrase = str_replace($healthy, $yummy, $phrase); echo $newphrase; // Use of the count parameter is available as of PHP 5.0.0 $str = str_replace("ll", "", "good golly miss molly!", $count); echo $count; // 2 $str="<p>this is test</p><br><p size=3>this.</p><p>hello</p>"; print str_replace(array('<p>','</p>','<br>'),array('<br>','<hr>',''),$str) ?>
php 的sub_replace函数对应的js函数为 String.prototype.replaceAll = function(search, replace){ var regex = new RegExp(search, "g"); return this.replace(regex, replace);
} var str = '<p>asfdafd</p><p>asfdafd</p><p>asfdafd</p>'; alert(str.replaceAll('</p>', '<br>'));
*************
在copy手册里的例子
<?php// Provides: <body text='black'>$bodytag = str_replace("%body%", "black", "<body text='%body%'>");// Provides: Hll Wrld f PHP$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");$onlyconsonants = str_replace($vowels, "", "Hello World of PHP");// Provides: You should eat pizza, beer, and ice cream every day$phrase = "You should eat fruits, vegetables, and fiber every day.";$healthy = array("fruits", "vegetables", "fiber");$yummy = array("pizza", "beer", "ice cream");$newphrase = str_replace($healthy, $yummy, $phrase);// Use of the count parameter is available as of PHP 5.0.0$str = str_replace("ll", "", "good golly miss molly!", $count);echo $count; // 2// Order of replacement$str = "Line 1/nLine 2/rLine 3/r/nLine 4/n";$order = array("/r/n", "/n", "/r");$replace = '<br />';// Processes /r/n's first so they aren't converted twice.$newstr = str_replace($order, $replace, $str);// Outputs: apearpearle pear$letters = array('a', 'p');$fruit = array('apple', 'pear');$text = 'a p';$output = str_replace($letters, $fruit, $text);echo $output;?>
- str-replace的认识-读fleaphp写
- str.replace替换的用法
- str=str.replace("<","!");
- str.replaceAll()和str.replace()的区别不可小视
- str.replace(/[ ]/g, "");
- 使用exslt str:replace template时遇到的问题
- VB-Instr、Str、Replace、Format
- python 写的str 解决dos2unix问题
- asp Replace的写方法大全
- python str.replace / str.endswith 以及 python语句(返回目录中所有JPG图像的文件名列表)
- JScript5.5下String.prototype.replace(str,func)的UBB嵌套的递归解开。
- 关于写博客的认识
- replace(str, "union", "union", 1, -1, 1)
- str.replace(old, new)小方法整理
- 【正则表达式】str.replace(reg, callback) 使用
- 使用str-replace而不是ereg-replace
- str[] , *str , static str[]的区别
- 一个认识的朋友写的
- 华为面试笔试谈
- c 语言中的函数参数
- PrintOut 方法
- 解决struts标签无法被默认选择的方法
- 锂电池的使用及注意事项
- str-replace的认识-读fleaphp写
- 建造(Builder)模式
- 学习 10 种良好的 XML 使用习惯
- 无法在WEB服务器上启动调试,问题解决办法
- 递归算法
- 递归算法
- Wordpress主题:Firebug
- 递归算法
- 递归算法