php实例之新浪星座运势

WBOY
풀어 주다: 2016-07-25 09:13:15
원래의
1588명이 탐색했습니다.

例子,php获取新浪星座与运势。

  1. function html2txt($document){

  2. $search = array('@<script>]*?>.*?</script>@si', // Strip out javascript
  3. '@]*?>@si', // Strip out HTML tags
  4. '@@siU', // Strip style tags properly
  5. '@@', // Strip multi-line comments including CDATA
  6. '@\s+| @'
  7. );
  8. $text = preg_replace($search, '', $document);
  9. return $text;
  10. } bbs.it-home.org
  11. function curl($url){
  12. $ch = curl_init();
  13. curl_setopt($ch, CURLOPT_URL, $url);
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  15. curl_setopt($ch, CURLOPT_REFERER, 'http://astro.sina.com.cn/fate/astro_aries.html?prourl=0');//伪造来源
  16. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/'.mt_rand(2, 9).'.0 (Windows NT 6.1; WOW64; rv:'.mt_rand(10, 30).'.0) Gecko/'.mt_rand(2000, 2014).'0101 Firefox/'.mt_rand(10, 30).'.0');//随机header
  17. curl_setopt($ch, CURLOPT_HEADER, 0);
  18. $data = curl_exec($ch);
  19. curl_close($ch);
  20. return $data;
  21. }
  22. foreach(array($constellation) as $astro){
  23. preg_match('/(.*?)(.*?).*?有效日期:(.*?)综合运势(.*?)爱情运势(.*?)工作状况(.*?)理财投资(.*?)健康指数(.*?)商谈指数(.*?)幸运颜色(.*?)幸运数字(.*?)速配星座(.*?)
    (.*?)/isu', curl('http://vip.astro.sina.com.cn/astro/view/'.$astro.'/day/'), $matches);
  24. file_put_contents($astro, json_encode(array($matches[1], $matches[2], html2txt($matches[3]), substr_count($matches[4], 'php实例之新浪星座运势 unset($matches);
  25. $array=json_decode(file_get_contents($astro),true);
  26. }
  27. //明天的日期
  28. $mingtian=date('Ymd',strtotime('+1 day'));
  29. foreach(array($constellation) as $astro){
  30. preg_match('/(.*?)(.*?).*?有效日期:(.*?)综合运势(.*?)爱情运势(.*?)工作状况(.*?)理财投资(.*?)健康指数(.*?)商谈指数(.*?)幸运颜色(.*?)幸运数字(.*?)速配星座(.*?)
    (.*?)/isu', curl('http://vip.astro.sina.com.cn/astro/view/'.$astro.'/day/'.$mingtian.''), $matches);
  31. //这样正则,可以更小的受新浪改版所带来的影响
  32. file_put_contents($astro, json_encode(array($matches[1], $matches[2], html2txt($matches[3]), substr_count($matches[4], 'php实例之新浪星座运势 unset($matches);

  33. $array2=json_decode(file_get_contents($astro),true);
  34. }
  35. //今天的运势
  36. print_r($array)
  37. //明天的运势
  38. print_r($array2)
  39. ?>
复制代码


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!