PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website đọc truyện online PHP/horoscope/func.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 207 lines | 44 code | 0 blank | 163 comment | 9 complexity | 786d1910d73fcbfa387c477dab91c776 MD5 | raw file
  1. <?php
  2. // Khai báo trình duyệt nhận lấy nội dung
  3. function userAgent() {
  4. $userAgent = 'Opera/9.80 (J2ME/MIDP; Opera Mini/4.3.24214/25.685; U; vi) Presto/2.5.25 Version/10.54';
  5. }
  6. // Khởi Tạo CURL
  7. function grab_link($url,$cookie='',$user_agent='',$header='') {
  8. if(function_exists('curl_init')){
  9. $ch = curl_init();
  10. $headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
  11. $headers[] = 'Accept-Language: en-us,en;q=0.5';
  12. $headers[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7';
  13. $headers[] = 'Keep-Alive: 300';
  14. $headers[] = 'Connection: Keep-Alive';
  15. $headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
  16. curl_setopt($ch, CURLOPT_URL, $url);
  17. if($user_agent) curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  18. else curl_setopt($ch, CURLOPT_USERAGENT, userAgent());
  19. if($header)
  20. curl_setopt($ch, CURLOPT_HEADER, 1);
  21. else
  22. curl_setopt($ch, CURLOPT_HEADER, 0);
  23. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  24. curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com.vn/search?hl=vi&client=firefox-a&rls=org.mozilla:en-US:official&hs=hKS&q=video+clip&start=20&sa=N');
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  26. if(strncmp($url, 'https', 6)) curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  27. if($cookie) curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  28. curl_setopt($ch, CURLOPT_TIMEOUT, 100);
  29. $html = curl_exec($ch);
  30. $mess_error = curl_error($ch);
  31. curl_close($ch);
  32. }
  33. else {
  34. $matches = parse_url($url);
  35. $host = $matches['host'];
  36. $link = (isset($matches['path'])?$matches['path']:'/').(isset($matches['query'])?'?'.$matches['query']:'').(isset($matches['fragment'])?'#'.$matches['fragment']:'');
  37. $port = !empty($matches['port']) ? $matches['port'] : 80;
  38. $fp=@fsockopen($host,$port,$errno,$errval,30);
  39. if (!$fp) {
  40. $html = "$errval ($errno)<br />\n";
  41. } else {
  42. $rand_ip = rand(1,254).".".rand(1,254).".".rand(1,254).".".rand(1,254);
  43. $out = "GET $link HTTP/1.1\r\n".
  44. "Host: $host\r\n".
  45. "Referer: http://www.google.com.vn/search?hl=vi&client=firefox-a&rls=org.mozilla:en-US:official&hs=hKS&q=video+clip&start=20&sa=N\r\n".
  46. "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
  47. if($cookie) $out .= "Cookie: $cookie\r\n";
  48. if($user_agent) $out .= "User-Agent: ".$user_agent."\r\n";
  49. else $out .= "User-Agent: ".userAgent()."\r\n";
  50. $out .= "X-Forwarded-For: $rand_ip\r\n".
  51. "Via: CB-Prx\r\n".
  52. "Connection: Close\r\n\r\n";
  53. fwrite($fp,$out);
  54. while (!feof($fp)) {
  55. $html .= fgets($fp,4096);
  56. }
  57. fclose($fp);
  58. }
  59. }
  60. return $html;
  61. }
  62. // Lấy nội dung
  63. function laynoidung($noidung, $start, $stop) {
  64. $bd = strpos($noidung, $start);
  65. $kt = strpos(substr($noidung, $bd), $stop) + $bd;
  66. $content = substr($noidung, $bd, $kt - $bd);
  67. return $content;
  68. }
  69. // Thay kí tự
  70. function trangkute($trang9x) {
  71. $trang9x = str_replace('Đ', '&#272;', $trang9x);
  72. $trang9x = str_replace('đ', '&#273;', $trang9x);
  73. $trang9x = str_replace('Á', '&#193;', $trang9x);
  74. $trang9x = str_replace('á', '&#225;', $trang9x);
  75. $trang9x = str_replace('À', '&#192;', $trang9x);
  76. $trang9x = str_replace('à', '&#224;', $trang9x);
  77. $trang9x = str_replace('Ã', '&#195;', $trang9x);
  78. $trang9x = str_replace('ã', '&#227;', $trang9x);
  79. $trang9x = str_replace('Ả', '&#7842;', $trang9x);
  80. $trang9x = str_replace('ả', '&#7843;', $trang9x);
  81. $trang9x = str_replace('Ạ', '&#7840;', $trang9x);
  82. $trang9x = str_replace('ạ', '&#7841;', $trang9x);
  83. $trang9x = str_replace('Â', '&#194;', $trang9x);
  84. $trang9x = str_replace('â', '&#226;', $trang9x);
  85. $trang9x = str_replace('Ấ', '&#7844;', $trang9x);
  86. $trang9x = str_replace('ấ', '&#7845;', $trang9x);
  87. $trang9x = str_replace('Ầ', '&#7846;', $trang9x);
  88. $trang9x = str_replace('ầ', '&#7847;', $trang9x);
  89. $trang9x = str_replace('Ẫ', '&#7850;', $trang9x);
  90. $trang9x = str_replace('ẫ', '&#7851;', $trang9x);
  91. $trang9x = str_replace('Ẩ', '&#7848;', $trang9x);
  92. $trang9x = str_replace('ẩ', '&#7849;', $trang9x);
  93. $trang9x = str_replace('Ậ', '&#7852;', $trang9x);
  94. $trang9x = str_replace('ậ', '&#7853;', $trang9x);
  95. $trang9x = str_replace('Ă', '&#258;', $trang9x);
  96. $trang9x = str_replace('ă', '&#259;', $trang9x);
  97. $trang9x = str_replace('Ắ', '&#7854;', $trang9x);
  98. $trang9x = str_replace('ắ', '&#7855;', $trang9x);
  99. $trang9x = str_replace('Ằ', '&#7856;', $trang9x);
  100. $trang9x = str_replace('ằ', '&#7857;', $trang9x);
  101. $trang9x = str_replace('Ẵ', '&#7860;', $trang9x);
  102. $trang9x = str_replace('ẵ', '&#7861;', $trang9x);
  103. $trang9x = str_replace('Ẳ', '&#7858;', $trang9x);
  104. $trang9x = str_replace('ẳ', '&#7859;', $trang9x);
  105. $trang9x = str_replace('Ặ', '&#7862;', $trang9x);
  106. $trang9x = str_replace('ặ', '&#7863;', $trang9x);
  107. $trang9x = str_replace('É', '&#201;', $trang9x);
  108. $trang9x = str_replace('é', '&#223;', $trang9x);
  109. $trang9x = str_replace('È', '&#200;', $trang9x);
  110. $trang9x = str_replace('è', '&#232;', $trang9x);
  111. $trang9x = str_replace('Ẽ', '&#7868;', $trang9x);
  112. $trang9x = str_replace('ẽ', '&#7869;', $trang9x);
  113. $trang9x = str_replace('Ẻ', '&#7866;', $trang9x);
  114. $trang9x = str_replace('ẻ', '&#7867;', $trang9x);
  115. $trang9x = str_replace('Ẹ', '&#7864;', $trang9x);
  116. $trang9x = str_replace('ẹ', '&#7865;', $trang9x);
  117. $trang9x = str_replace('Ê', '&#202;', $trang9x);
  118. $trang9x = str_replace('ê', '&#234;', $trang9x);
  119. $trang9x = str_replace('Ế', '&#7870;', $trang9x);
  120. $trang9x = str_replace('ế', '&#7871;', $trang9x);
  121. $trang9x = str_replace('Ề', '&#7872;', $trang9x);
  122. $trang9x = str_replace('ề', '&#7873;', $trang9x);
  123. $trang9x = str_replace('Ễ', '&#7876;', $trang9x);
  124. $trang9x = str_replace('ễ', '&#7877;', $trang9x);
  125. $trang9x = str_replace('Ể', '&#7874;', $trang9x);
  126. $trang9x = str_replace('ể', '&#7875;', $trang9x);
  127. $trang9x = str_replace('Ệ', '&#7878;', $trang9x);
  128. $trang9x = str_replace('ệ', '&#7879;', $trang9x);
  129. $trang9x = str_replace('Í', '&#205;', $trang9x);
  130. $trang9x = str_replace('í', '&#237;', $trang9x);
  131. $trang9x = str_replace('Ì', '&#204;', $trang9x);
  132. $trang9x = str_replace('ì', '&#236;', $trang9x);
  133. $trang9x = str_replace('Ĩ', '&#296;', $trang9x);
  134. $trang9x = str_replace('ĩ', '&#297;', $trang9x);
  135. $trang9x = str_replace('Ỉ', '&#7880;', $trang9x);
  136. $trang9x = str_replace('ỉ', '&#7881;', $trang9x);
  137. $trang9x = str_replace('Ị', '&#7882;', $trang9x);
  138. $trang9x = str_replace('ị', '&#7883;', $trang9x);
  139. $trang9x = str_replace('Ó', '&#221;', $trang9x);
  140. $trang9x = str_replace('ó', '&#243;', $trang9x);
  141. $trang9x = str_replace('Ò', '&#210;', $trang9x);
  142. $trang9x = str_replace('ò', '&#242;', $trang9x);
  143. $trang9x = str_replace('Õ', '&#213;', $trang9x);
  144. $trang9x = str_replace('õ', '&#245;', $trang9x);
  145. $trang9x = str_replace('Ỏ', '&#7886;', $trang9x);
  146. $trang9x = str_replace('ỏ', '&#7887;', $trang9x);
  147. $trang9x = str_replace('Ọ', '&#7884;', $trang9x);
  148. $trang9x = str_replace('ọ', '&#7885;', $trang9x);
  149. $trang9x = str_replace('Ô', '&#212;', $trang9x);
  150. $trang9x = str_replace('ô', '&#244;', $trang9x);
  151. $trang9x = str_replace('Ố', '&#7888;', $trang9x);
  152. $trang9x = str_replace('ố', '&#7889;', $trang9x);
  153. $trang9x = str_replace('Ồ', '&#7890;', $trang9x);
  154. $trang9x = str_replace('ồ', '&#7891;', $trang9x);
  155. $trang9x = str_replace('Ỗ', '&#7894;', $trang9x);
  156. $trang9x = str_replace('ỗ', '&#7895;', $trang9x);
  157. $trang9x = str_replace('Ổ', '&#7892;', $trang9x);
  158. $trang9x = str_replace('ổ', '&#7893;', $trang9x);
  159. $trang9x = str_replace('Ộ', '&#7896;', $trang9x);
  160. $trang9x = str_replace('ộ', '&#7897;', $trang9x);
  161. $trang9x = str_replace('Ơ', '&#416;', $trang9x);
  162. $trang9x = str_replace('ơ', '&#417;', $trang9x);
  163. $trang9x = str_replace('Ớ', '&#7898;', $trang9x);
  164. $trang9x = str_replace('ớ', '&#7899;', $trang9x);
  165. $trang9x = str_replace('Ờ', '&#7900;', $trang9x);
  166. $trang9x = str_replace('ờ', '&#7901;', $trang9x);
  167. $trang9x = str_replace('Ỡ', '&#7904;', $trang9x);
  168. $trang9x = str_replace('ỡ', '&#7905;', $trang9x);
  169. $trang9x = str_replace('Ở', '&#7902;', $trang9x);
  170. $trang9x = str_replace('ở', '&#7903;', $trang9x);
  171. $trang9x = str_replace('Ợ', '&#7906;', $trang9x);
  172. $trang9x = str_replace('ợ', '&#7907;', $trang9x);
  173. $trang9x = str_replace('Ú', '&#218;', $trang9x);
  174. $trang9x = str_replace('ú', '&#250;', $trang9x);
  175. $trang9x = str_replace('Ù', '&#217;', $trang9x);
  176. $trang9x = str_replace('ù', '&#249;', $trang9x);
  177. $trang9x = str_replace('Ũ', '&#360;', $trang9x);
  178. $trang9x = str_replace('ũ', '&#361;', $trang9x);
  179. $trang9x = str_replace('Ủ', '&#7910;', $trang9x);
  180. $trang9x = str_replace('ủ', '&#7911;', $trang9x);
  181. $trang9x = str_replace('Ụ', '&#7908;', $trang9x);
  182. $trang9x = str_replace('ụ', '&#7909;', $trang9x);
  183. $trang9x = str_replace('Ư', '&#431;', $trang9x);
  184. $trang9x = str_replace('ư', '&#432;', $trang9x);
  185. $trang9x = str_replace('Ứ', '&#7912;', $trang9x);
  186. $trang9x = str_replace('ứ', '&#7913;', $trang9x);
  187. $trang9x = str_replace('Ừ', '&#7914;', $trang9x);
  188. $trang9x = str_replace('ừ', '&#7915;', $trang9x);
  189. $trang9x = str_replace('Ữ', '&#7918;', $trang9x);
  190. $trang9x = str_replace('ữ', '&#7919;', $trang9x);
  191. $trang9x = str_replace('Ử', '&#7916;', $trang9x);
  192. $trang9x = str_replace('ử', '&#7917;', $trang9x);
  193. $trang9x = str_replace('Ự', '&#7920;', $trang9x);
  194. $trang9x = str_replace('ự', '&#7921;', $trang9x);
  195. $trang9x = str_replace('Ý', '&#221;', $trang9x);
  196. $trang9x = str_replace('ý', '&#253;', $trang9x);
  197. $trang9x = str_replace('Ỳ', '&#7922;', $trang9x);
  198. $trang9x = str_replace('ỳ', '&#7923;', $trang9x);
  199. $trang9x = str_replace('Ỹ', '&#7928;', $trang9x);
  200. $trang9x = str_replace('ỹ', '&#7929;', $trang9x);
  201. $trang9x = str_replace('Ỷ', '&#7926;', $trang9x);
  202. $trang9x = str_replace('ỷ', '&#7927;', $trang9x);
  203. $trang9x = str_replace('Ỵ', '&#7924;', $trang9x);
  204. $trang9x = str_replace('ỵ', '&#7925;', $trang9x);
  205. return $trang9x;
  206. }
  207. ?>