来自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 ( '/\]*?)\>/si', '<\\1script\\2>', $str );
- $str = preg_replace ( '/\]*?)\>/si', '<\\1iframe\\2>', $str );
- $str = preg_replace ( '/\]*?)\>/si', '<\\1frame\\2>', $str );
- $str = preg_replace ( '/]]\>/si', ']] >', $str );
- }
- return $str;
- }
复制代码
|