Home > Backend Development > PHP Tutorial > A relatively comprehensive interception function (mostly used for analysis of collected content)

A relatively comprehensive interception function (mostly used for analysis of collected content)

WBOY
Release: 2016-07-25 09:07:09
Original
932 people have browsed it
  1. /*

  2. Collection and interception function, mainly used to analyze the collected content
  3. getcon - remove html characters and spaces after interception
  4. getcon2 - simple interception, directly return the interception content.
  5. Parameters:
  6. $par accepts two formats:
  7. 1. Characters before {DATA} and characters after
  8. 2. Regular expression
  9. */

  10. function getcon($pat,$str) {

  11. $title_var=explode("{DATA}",$pat);
  12. if(count($title_var)>1){
  13. $title_1=explode($title_var[0],$str);
  14. $title_2= explode($title_var[1],$title_1[1]);
  15. return strip_s(strip_tags($title_2[0]));
  16. }else{
  17. preg_match_all($pat,$str,$res);
  18. return strip_s( strip_tags($res[1][0]));
  19. }
  20. }
  21. function getcon2($pat,$str){
  22. $title_var=explode ("{DATA}",$pat);
  23. if(count( $title_var)>1){
  24. $title_1=explode($title_var[0],$str);
  25. $title_2=explode($title_var[1],$title_1[1]);
  26. return $title_2[0] ;
  27. }else{
  28. preg_match_all($pat,$str,$res);
  29. return $res[1][0];
  30. }
  31. }
  32. function strip_s($str){
  33. $str = preg_replace ("/ (s+)/", ' ', $str);
  34. $str = str_replace(chr(13),'',$str);
  35. $str = str_replace(chr(10),'
    ',$ str);
  36. $str = ltrim($str);
  37. $str = trim($str);
  38. return $str;
  39. }
  40. ?>

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