1.是针对35dir程序获取pr问题
2.是独立的PHP获取pr程序
1.针对35dirpr值获取问题
修改\source\module\webdate.php
搜索 get_pagerank函数 修改为以下代码 即可
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function get_pagerank($url) { //require(APP_PATH.'include/pagerank.php'); //$pr = new PageRank(); //$rank = $pr->getGPR($url); //return $rank; $data = get_url_content("http://pr.linkhelper.cn/getpr.asp?queryurl=$url&show=1"); if (preg_match('/<a(.*?)>(\d+)<\/a>/i', $data, $matches)) { $rank = intval($matches[2]); } else { $rank = 0; } return $rank; } |
2.PHP通用获取PR值 以下代码保存为pr.php放在根目录 调用方法 www.xxx.com/pr.php?url=skyfox.org
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
<?php $url=$_GET['url']; $data = get_url_content("http://pr.linkhelper.cn/getpr.asp?queryurl=$url&show=1"); preg_match('/<a(.*?)>(\d+)<\/a>/i', $data, $matches); $rank = intval($matches[2]); print_r($rank); /** 获取指定URL内容 */ function get_url_content($url) { if (empty($url)) { return false; } if (substr($url, 0, 7) != 'http://') { $url = 'http://'.$url; } $timeout = 30; $data = ''; for ($i = 0; $i < 5 && empty($data); $i++) { if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); $data = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code != '200') { return false; } } elseif (function_exists('fsockopen')) { $params = parse_url($url); $host = $params['host']; $path = $params['path']; $query = $params['query']; $fp = @fsockopen($host, 80, $errno, $errstr, $timeout); if (!$fp) { return false; } else { $result = ''; $out = "GET /" . $path . '?' . $query . " HTTP/1.0\r\n"; $out .= "Host: $host\r\n"; $out .= "Connection: Close\r\n\r\n"; @fwrite($fp, $out); $http_200 = preg_match('/HTTP.*200/', @fgets($fp, 1024)); if (!$http_200) { return false; } while (!@feof($fp)) { if ($get_info) { $data .= @fread($fp, 1024); } else { if (@fgets($fp, 1024) == "\r\n") { $get_info = true; } } } @fclose($fp); } } elseif (function_exists( 'file_get_contents')) { if (!get_cfg_var('allow_url_fopen')) { return false; } $context = stream_context_create( array('http' => array('timeout' => $timeout)) ); $data = @file_get_contents($url, false, $context); } else { return false; } } if (!$data) { return false; } else { $encode = mb_detect_encoding($data, array('ascii', 'gb2312', 'utf-8', 'gbk')); if ($encode == 'EUC-CN' || $encode == 'CP936') { $data = @mb_convert_encoding($data, 'utf-8', 'gb2312'); } return $data; } } |
转载请注明:天狐博客 » 2013最新可用php获取谷歌pr值方法