Home >Backend Development >PHP Tutorial >过滤掉一些字符有关问题

过滤掉一些字符有关问题

WBOY
WBOYOriginal
2016-06-13 10:27:27874browse

过滤掉一些字符问题
91#col#投药中和#row#97#col#JiaoTiLiZi.gif#row#98#col#萃取#row#99#col#FenPeiXiShu.GIF#row#

结构是这样:id + #col# + 名字 + #row#
91#col#投药中和#row# 97#col#JiaoTiLiZi.gif#row# 

很多这样的数据,要处理掉gif

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$contents = preg_replace('/[\w]#col#(.*?).gif#row#'/i,'',$contents);


我想这样替换成空,这种方法是不是不太好呢?
而且这个正则有错

------解决方案--------------------
若处理的是固定的字符串可以用 str_replace()函数
------解决方案--------------------
这样?
PHP code
$str="91#col#投药中和#row#97#col#JiaoTiLiZi.gif#row#98#col#萃取#row#99#col#FenPeiXiShu.GIF#row#";$str=preg_replace('/#[\d]+#col#[a-z]+.gif#row#/is','#',$str);echo $str;<br><font color="#e78608">------解决方案--------------------</font><br>
PHP code
$contents = preg_replace('/(col#[^\.]+)\.gif(#row)/i','$1$2',$s);echo $contents;<br><font color="#e78608">------解决方案--------------------</font><br>
PHP code
$str='91#col#投药中和#row#97#col#JiaoTiLiZi.gif#row#98#col#萃取#row#99#col#FenPeiXiShu.GIF#row#';echo preg_replace('/\d*#col#[^#]*(?
                 
              
              
        
            
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn