转义javascript代码标记函数
时间:2021-07-01 10:21:17
帮助过:18人阅读
来自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;
- }
|