《PHP實(shí)例:10個(gè)超級(jí)有用值得收藏的PHP代碼片段》要點(diǎn):
本文介紹了PHP實(shí)例:10個(gè)超級(jí)有用值得收藏的PHP代碼片段,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
PHP編程// create a new cURL resource
$ch = curl_init();
PHP編程// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
PHP編程// grab URL and pass it to the browser
$opt = curl_exec($ch);
PHP編程// close cURL resource, and free up system resources
curl_close($ch);
PHP編程$saveFile = $name.'.'.$ext;
if(preg_match("/[^0-9a-z._-]/i", $saveFile))
??? $saveFile = md5(microtime(true)).'.'.$ext;
PHP編程$handle = fopen($saveFile, 'wb');
fwrite($handle, $opt);
fclose($handle);
四、Alexa/Google Page Rank
PHP編程function page_rank($page, $type = 'alexa'){
??? switch($type){
??????? case 'alexa':
??????????? $url = 'http://alexa.com/siteinfo/';
??????????? $handle = fopen($url.$page, 'r');
??????? break;
??????? case 'google':
??????????? $url = 'http://google.com/search必修client=navclient-auto&ch=6-1484155081&features=Rank&q=info:';
??????????? $handle = fopen($url.'http://'.$page, 'r');
??????? break;
??? }
??? $content = stream_get_contents($handle);
??? fclose($handle);
??? $content = preg_replace("~(n|t|ss+)~",'', $content);
??? switch($type){
??????? case 'alexa':
??????????? if(preg_match('~<div class="data (down|up)"><img.+必修>(.+必修) </div>~im',$content,$matches)){
??????????????? return $matches[2];
??????????? }else{
??????????????? return FALSE;
??????????? }
??????? break;
??????? case 'google':
??????????? $rank = explode(':',$content);
??????????? if($rank[2] != '')
??????????????? return $rank[2];
??????????? else
??????????????? return FALSE;
??????? break;
??????? default:
??????????? return FALSE;
??????? break;
??? }
}
// Alexa Page Rank:
echo 'Alexa Rank: '.page_rank('techug.com');
echo '
';
// Google Page Rank
echo 'Google Rank: '.page_rank('techug.com', 'google');
《PHP實(shí)例:10個(gè)超級(jí)有用值得收藏的PHP代碼片段》是否對(duì)您有啟發(fā),歡迎查看更多與《PHP實(shí)例:10個(gè)超級(jí)有用值得收藏的PHP代碼片段》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/12580.html