Escape javascript code tag function

WBOY
Release: 2016-07-25 09:08:33
Original
1356 people have browsed it
来自PHPCMS
  1. /**
  2. * 转义 javascript 代码标记
  3. *
  4. * @param $str
  5. * @return mixed
  6. */
  7. function trim_script($str) {
  8. if(is_array($str)){
  9. foreach ($str as $key => $val){
  10. $str[$key] = trim_script($val);
  11. }
  12. }else{
  13. $str = preg_replace ( '/\<([\/]?)script([^\>]*?)\>/si', '<\\1script\\2>', $str );
  14. $str = preg_replace ( '/\<([\/]?)iframe([^\>]*?)\>/si', '<\\1iframe\\2>', $str );
  15. $str = preg_replace ( '/\<([\/]?)frame([^\>]*?)\>/si', '<\\1frame\\2>', $str );
  16. $str = preg_replace ( '/]]\>/si', ']] >', $str );
  17. }
  18. return $str;
  19. }
复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!