PHP Examples of Sina constellation horoscope

Source: Internet
Author: User

Example, PHP gets Sina constellation and horoscope.

  1. function Html2txt ($document) {

  2. $search = Array (' @ @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 ');//Forged Source
  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 ');//Random 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 ('/(. *?) (.*?) <\/em><\/span>.*? Date of validity: (. *?) Integrated Horoscope (. *?) Love Horoscope (. *?) Work status (. *?) Financial investment (. *?) Health index (. *?) Negotiation index (. *?) Lucky Color (. *?) Lucky number (. *?) Speed dating (. *?) (.*?) <\/div>/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], ' unset ($matches);
  25. $array =json_decode (file_get_contents ($astro), true);
  26. }
  27. Tomorrow's date
  28. $mingtian =date (' Ymd ', Strtotime (' +1 Day '));
  29. foreach (Array ($constellation) as $astro) {
  30. Preg_match ('/(. *?) (.*?) <\/em><\/span>.*? Date of validity: (. *?) Integrated Horoscope (. *?) Love Horoscope (. *?) Work status (. *?) Financial investment (. *?) Health index (. *?) Negotiation index (. *?) Lucky Color (. *?) Lucky number (. *?) Speed dating (. *?) (.*?) <\/div>/isu ', curl (' http://vip.astro.sina.com.cn/astro/view/'. $astro. ' /day/'. $mingtian. '), $matches);
  31. Such a regular, can be smaller by the impact of the Sina revision

  32. File_put_contents ($astro, Json_encode (Array ($matches [1], $matches [2], Html2txt ($matches [3]), Substr_count ($matches [4], ' unset ($matches);

  33. $array 2=json_decode (file_get_contents ($astro), true);
  34. }
  35. Today's horoscope
  36. Print_r ($array)
  37. Tomorrow's horoscope
  38. Print_r ($array 2)
  39. ?>

Copy Code
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.