Home >Backend Development >PHP Tutorial >PHP collects Tencent Weibo and only leaves the text part

PHP collects Tencent Weibo and only leaves the text part

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:44:26883browse
PHP collects only the text part of Tencent Weibo
  1. header("Content-type: text/html;charset=utf-8");
  2. $weibo = file_get_contents('http://t. qq.com/starank');
  3. $preg = '/
    (.*)
    /Uis';
  4. preg_match_all ($preg, $weibo, $string);
  5. foreach ($string[1] as $key=>$value){
  6. echo delhtml($value)."

    ";
  7. }
  8. function delhtml($str) // Clear html tag
  9. {
  10. $st = -1; //Start
  11. $et = -1; //End
  12. $stmp = array();
  13. $stmp[] = " ";
  14. $len = strlen($str);
  15. for($i = 0;$i < $len;$i++)
  16. {
  17. $ss = substr($ str, $i, 1);
  18. if (ord($ss) == 60) // ord("<")==60
  19. {
  20. $st = $i;
  21. }
  22. if (ord($ss ) == 62) // ord(">")==62
  23. {
  24. $et = $i;
  25. if ($st != -1)
  26. {
  27. $stmp[] = substr($str, $ st, $et - $st + 1);
  28. }
  29. }
  30. }
  31. $str = str_replace($stmp, "", $str);
  32. return $str;
  33. }
  34. ?>
Copy code

Only left, PHP


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