常用正则
1.使用正则表达式删除
|
1
|
$text = preg_replace('/\r\n|\r|\n/','',$text); |
2.删除使用字符串功能
|
1
2
3
|
$text = str_replace(array("\r\n","\r","\n"),'',$text); 또는$text = strtr($text,array("\r\n"=>'',"\r"=>'',"\n"=>'')); |
删除html标签
|
1
|
$content = preg_replace("(\<(/?[^\>]+)\>)", "", $content); |
删除textarea
|
1
2
|
$content = preg_replace("!<textarea(.*?)>!is","[textarea]",$content);$content = preg_replace("!</textarea(.*?)>!is","[/textarea]",$content); |
删除脚本
|
1
|
$str=preg_replace("!<script(.*?)<\/script>!is","",$str); |
删除iframe
|
1
|
$str=preg_replace("!<iframe(.*?)<\/iframe>!is","",$str); |
元删除
|
1
|
$str=preg_replace("!<meta(.*?)>!is","",$str); |
删除样式标记
|
1
|
$str=preg_replace("!<style(.*?)<\/style>!is","",$str); |
&nbsp;到空白
|
1
|
$str=str_replace(" "," ",$str); |
有一个连续的空间
|
1
|
$str=preg_replace("/\s{2,}/"," ",$str); |
删除标签内的style =属性
|
1
2
|
$str=preg_replace("/ zzstyle=([^\"\']+) /"," ",$str); // style=border:0 따옴표가 없을때$str=preg_replace("/ style=(\"|\')?([^\"\']+)(\"|\')?/","",$str); // style="border:0" 따옴표 있을때 |
删除标签width =,height = attribute
|
1
2
|
$str=preg_replace("/ width=(\"|\')?\d+(\"|\')?/","",$str);$str=preg_replace("/ height=(\"|\')?\d+(\"|\')?/","",$str); |
img extract标签src提取
|
1
2
|
preg_match("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i",$str,$result);preg_match_all("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i",$str,$result); |
删除特殊字符
|
1
|
$string = preg_replace("/[ #\&\+\-%@=\/\\\:;,\.'\"\^`~\_|\!\?\*$#<>()\[\]\{\}]/i", "", $string); |
删除空格
|
1
2
|
$string = preg_replace('/ /', '', $string);$string = preg_replace("/\s+/", "", $string); |
删除重复输入的单词
|
1
|
$string = preg_replace("/s(w+s)1/i", "$1", $string); |
删除重复输入的标志
|
1
|
$string = preg_replace("/.+/i", ".", $string); |
删除除字母字符以外的所有字符
|
1
|
$string = preg_replace("/[^A-Za-z]/", "", $string); |
删除除字母字符和空格字符(空格)以外的所有字符
|
1
|
$string = preg_replace("/[^A-Za-z|\x20]/", "", $string); |
ASCII类别代码删除除英语+特殊字符外的所有字符
|
1
|
$string = preg_replace("/[^\x20-\x7e]/", "", $string); |
提取img标签
|
1
2
|
preg_match_all("/<img[^>]*src=[\'\"]?([^>\'\"]+)[\'\"]?[^>]*>/", $img, $matchs);print_r($matchs);
|
FIGHTING---EVEREY BODY

浙公网安备 33010602011771号