<?php
class OTagString
{
* 截取字符串中某一段内容
* @param $str
* @param $start_str string 开始字符串或标签提示
* @param $end_str string 结束字符串或标签提示
* @return bool|string
*/
function get_str($str,$start_str,$end_str){
$start_pos = strpos($str,$start_str)+strlen($start_str);
$end_pos = strpos($str,$end_str);
$c_str_l = $end_pos - $start_pos;
$contents = substr($str,$start_pos,$c_str_l);
return $contents;
}
* 过滤掉字符串中所有指定位置的内容
* @param $str
* @param $start_str string 开始字符串或标签提示
* @param $end_str string 结束字符串或标签提示
* @return mixed
*/
function clear_str($str,$start_str,$end_str){
$s = "{".$start_str."[\s\S]*?".$end_str."}si";
return preg_replace($s,"\n",$str);
}
* 指定字符串中内容/标签替换
* @param $string
* @param $replacer array 替换的原内容=>现内容的一维数组
* @return mixed
*/
function stringParser($string,$replacer){
$result = str_replace(array_keys($replacer), array_values($replacer),$string);
return $result;
}
* 过滤所有的html标签,保留纯文本格式
* @param $area_str
* @return mixed|string
*/
function clear_html_tags($area_str){
if ($area_str!=''){
$area_str = trim($area_str);
$area_str = strip_tags($area_str,"");
$area_str = str_replace(" ","",$area_str);
$area_str = preg_replace("/ /","",$area_str);
$area_str = preg_replace("/
/","",$area_str);
$area_str = preg_replace("/
/","",$area_str);
$area_str = preg_replace("/
/","",$area_str);
$area_str = preg_replace("/ /","",$area_str);
$area_str = preg_replace("/ /","",$area_str);
$area_str = trim($area_str);
}
return $area_str;
}
* 其它过滤方法1(过滤html其它标签)
* @param $str
* @return mixed
*/
function strFilter1($str){
$str=preg_replace("/\s+/", " ", $str);
$str=preg_replace("/<[ ]+/si","<",$str);
$str=preg_replace("/<\!–.*?–>/si","",$str);
$str=preg_replace("/<(\!.*?)>/si","",$str);
$str=preg_replace("/<(\/?html.*?)>/si","",$str);
$str=preg_replace("/<(\/?head.*?)>/si","",$str);
$str=preg_replace("/<(\/?meta.*?)>/si","",$str);
$str=preg_replace("/<(\/?body.*?)>/si","",$str);
$str=preg_replace("/<(\/?link.*?)>/si","",$str);
$str=preg_replace("/<(\/?form.*?)>/si","",$str);
$str=preg_replace("/cookie/si","COOKIE",$str);
$str=preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si","",$str);
$str=preg_replace("/<(\/?applet.*?)>/si","",$str);
$str=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$str);
$str=preg_replace("/<(\/?style.*?)>/si","",$str);
$str=preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si","",$str);
$str=preg_replace("/<(\/?title.*?)>/si","",$str);
$str=preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si","",$str);
$str=preg_replace("/<(\/?objec.*?)>/si","",$str);
$str=preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si","",$str);
$str=preg_replace("/<(\/?noframes.*?)>/si","",$str);
$str=preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si","",$str);
$str=preg_replace("/<(\/?i?frame.*?)>/si","",$str);
$str=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$str);
$str=preg_replace("/<(\/?script.*?)>/si","",$str);
$str=preg_replace("/javascript/si","Javascript",$str);
$str=preg_replace("/vbscript/si","Vbscript",$str);
$str=preg_replace("/on([a-z]+)\s*=/si","On\\1=",$str);
$str=preg_replace("/&#/si","&#",$str);
return $str;
}
*其它过滤方法2:过滤特殊字符和sql关键字
* @param $str
* @return string
*/
function strFilter2($str){
$str = str_replace('`', '', $str);
$str = str_replace('·', '', $str);
$str = str_replace('~', '', $str);
$str = str_replace('!', '', $str);
$str = str_replace('!', '', $str);
$str = str_replace('@', '', $str);
$str = str_replace('#', '', $str);
$str = str_replace('$', '', $str);
$str = str_replace('¥', '', $str);
$str = str_replace('%', '', $str);
$str = str_replace('^', '', $str);
$str = str_replace('……', '', $str);
$str = str_replace('&', '', $str);
$str = str_replace('*', '', $str);
$str = str_replace('(', '', $str);
$str = str_replace(')', '', $str);
$str = str_replace('(', '', $str);
$str = str_replace(')', '', $str);
$str = str_replace('-', '', $str);
$str = str_replace('_', '', $str);
$str = str_replace('——', '', $str);
$str = str_replace('+', '', $str);
$str = str_replace('=', '', $str);
$str = str_replace('|', '', $str);
$str = str_replace('\\', '', $str);
$str = str_replace('[', '', $str);
$str = str_replace(']', '', $str);
$str = str_replace('【', '', $str);
$str = str_replace('】', '', $str);
$str = str_replace('{', '', $str);
$str = str_replace('}', '', $str);
$str = str_replace(';', '', $str);
$str = str_replace(';', '', $str);
$str = str_replace(':', '', $str);
$str = str_replace(':', '', $str);
$str = str_replace('\'', '', $str);
$str = str_replace('"', '', $str);
$str = str_replace('“', '', $str);
$str = str_replace('”', '', $str);
$str = str_replace(',', '', $str);
$str = str_replace(',', '', $str);
$str = str_replace('<', '', $str);
$str = str_replace('>', '', $str);
$str = str_replace('《', '', $str);
$str = str_replace('》', '', $str);
$str = str_replace('.', '', $str);
$str = str_replace('。', '', $str);
$str = str_replace('/', '', $str);
$str = str_replace('、', '', $str);
$str = str_replace('?', '', $str);
$str = str_replace('?', '', $str);
$str = str_replace('and','',$str);
$str = str_replace('execute','',$str);
$str = str_replace('update','',$str);
$str = str_replace('count','',$str);
$str = str_replace('chr','',$str);
$str = str_replace('mid','',$str);
$str = str_replace('master','',$str);
$str = str_replace('truncate','',$str);
$str = str_replace('char','',$str);
$str = str_replace('declare','',$str);
$str = str_replace('select','',$str);
$str = str_replace('create','',$str);
$str = str_replace('delete','',$str);
$str = str_replace('insert','',$str);
$str = str_replace('or','',$str);
return trim($str);
}
}