来自PHPCMS
- /**
- * 转义 javascript 代码标记
- *
- * @param $str
- * @return mixed
- */
- function trim_script($str) {
- if(is_array($str)){
- foreach ($str as $key => $val){
- $str[$key] = trim_script($val);
- }
- }else{
- $str = preg_replace ( '/\<([\/]?)script([^\>]*?)\>/si', '<\\1script\\2>', $str );
- $str = preg_replace ( '/\<([\/]?)iframe([^\>]*?)\>/si', '<\\1iframe\\2>', $str );
- $str = preg_replace ( '/\<([\/]?)frame([^\>]*?)\>/si', '<\\1frame\\2>', $str );
- $str = preg_replace ( '/]]\>/si', ']] >', $str );
- }
- return $str;
- }
复制代码
|