Home >Backend Development >PHP Tutorial >Escape javascript code tag function

Escape javascript code tag function

WBOY
WBOYOriginal
2016-07-25 09:08:331445browse
来自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. }
复制代码


Statement:
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