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

过滤掉一些字符有关问题

WBOY
Release: 2016-06-13 13:27:52
Original
889 people have browsed it

过滤掉一些字符问题
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);


Copy after login


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

------解决方案--------------------
若处理的是固定的字符串可以用 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>
Copy after login
PHP code
$contents = preg_replace('/(col#[^\.]+)\.gif(#row)/i','$1$2',$s);
echo $contents;
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
PHP code
$str='91#col#投药中和#row#97#col#JiaoTiLiZi.gif#row#98#col#萃取#row#99#col#FenPeiXiShu.GIF#row#';

echo preg_replace('/\d*#col#[^#]*(?
                 
              
              
        
            
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template