php实例之新浪星座运势

php中文网
发布: 2016-07-25 09:13:15
原创
1771人浏览过

例子,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);

    阶跃星辰开放平台
    阶跃星辰开放平台

    阶跃星辰旗下开放平台,提供文本大模型、多模态大模型、繁星计划

    阶跃星辰开放平台 0
    查看详情 阶跃星辰开放平台
  33. $array2=json_decode(file_get_contents($astro),true);
  34. }
  35. //今天的运势
  36. print_r($array)
  37. //明天的运势
  38. print_r($array2)
  39. ?>
复制代码


PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号