Home > Backend Development > PHP Tutorial > Usage of htmlspecialchars and htmlentiti in php

Usage of htmlspecialchars and htmlentiti in php

WBOY
Release: 2016-07-25 09:13:21
Original
1057 people have browsed it

In PHP programming, after using file_get_contents to get the web page, if you directly use echo to output, the browser output will be automatically parsed, and the output will still be the web page.

Use htmlspecialchars to convert the obtained content, and then get all the links. intercept.

There will be problems when intercepting,

Intercept content converted using htmlspecialchars, interception method:

  1. $word = substr($str,strpos($str,'>',5)+4,strpos($str,"<",10)-strpos($str,'>',5 )-4);
  2. function captureKeyArray($url)
  3. {
  4. $content=file_get_contents($url);
  5. $pattern="//imsU";
  6. $match = array();
  7. preg_match_all($pattern,$content,$match);
  8. $matchFilter = array();
  9. foreach($match[0] as $key=>$val)
  10. {
  11. $str= htmlspecialchars ($val);
  12. if(strpos($str,"img"))
  13. {
  14. }
  15. else
  16. {
  17. //Why can't you filter out < instead, use <
  18. $word = substr($str,strpos ($str,'>',5)+4,strpos($str,"<",10)-strpos($str,'>',5)-4);
  19. if($word!="")
  20. {
  21. array_push($matchFilter,$word);
  22. }
  23. }
  24. }
  25. return $matchFilter;
  26. }
Copy code


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