function curl_file($url) { if (check_remote_file_exists($url) == '1') { // 创建一个新CURL资源 $ch = curl_init(); // 设置URL和相应的选项 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // 抓取URL并把它传递给浏览器 return curl_exec($ch); // 关闭CURL资源,并且释放系统资源 curl_close($ch); } else { return false; } }
public function getFavicon() { $parseurl = parse_url($this->_url); $host = $parseurl['host']; if ($parseurl['scheme'] == 'https') { $parseurl['scheme'] = 'http'; } $host = preg_replace("/^www./", '', $host); //strstr('.',$host); $ico = $parseurl['scheme'] . '://' . $host . '/favicon.ico'; $ico_not_www = $parseurl['scheme'] . '://www.' . $host . '/favicon.ico'; if (check_remote_file_exists($ico, $this->_proxy)) { return $ico; } elseif (check_remote_file_exists($ico_not_www, $this->_proxy)) { return $ico_not_www; } else { if (!$this->_content) { $this->_content = dzz_file_get_contents($this->_url, $this->_redirect, $this->_proxy); } if (preg_match("/<link(.+?)rel=\"[shortcut\\s+icon|shortcut|icon]+\"(.+?)>/i", $this->_content, $matches2)) { if (preg_match("/href=\"(.+?)\"/i", $matches2[0], $matches3)) { $ico = trim($matches3[1]); $purl = parse_url($ico); if (empty($purl['host'])) { //exit('dfdsf'); $ico0 = $parseurl['scheme'] . '://' . preg_replace("/\\/\\//i", '/', $host . '/' . $ico); $ico1 = $parseurl['scheme'] . '://' . preg_replace("/\\/\\//i", '/', 'www.' . $host . '/' . $ico); } else { $ico0 = $ico1 = preg_replace("/^https/i", 'http', $ico); } //exit($ico0.'===='.$ico1); if (check_remote_file_exists($ico1, $this->_proxy)) { return $ico1; } if (check_remote_file_exists($ico0, $this->_proxy)) { return $ico0; } } } } return ''; }
$result = curl_exec($curl); $found = false; if ($result !== false) { $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($statusCode == 200) { $found = true; } } curl_close($curl); return $found; } if (isset($_GET["p"])) { if ($_GET["p"] == "url" && isset($_POST["url"])) { $url = htmlspecialchars($_POST['url']); $check = preg_match('/^((http|https):\\/\\/)?(\\w(\\:\\w)?@)?([0-9a-z_-]+\\.)*?([a-z0-9-]+\\.[a-z]{2,6}(\\.[a-z]{2})?(\\:[0-9]{2,6})?)((\\/[^?#<>\\/\\*":]*)+(\\?[^#]*)?(#.*)?)?$/i', $url); if ($check == 0 || check_remote_file_exists($url) == false) { echo "网址有误"; } else { include_once 'phpQuery.php'; phpQuery::newDocumentFile($url); $title = pq("title")->text(); echo mb_strimwidth(trim($title), 0, 24, '...', 'utf-8'); } } if ($_GET["p"] == "qq" && isset($_POST["qq"])) { $qq = htmlspecialchars($_POST['qq']); $str = file_get_contents("http://base.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins=" . $qq); $c = iconv("gb2312", "utf-8//IGNORE", $str); $c = mb_convert_encoding($str, "UTF-8", "GBK"); $json = mb_substr(trim($c), 17, -1, 'utf-8'); $jsonstr = json_decode($json, true);