ホームページ  >  記事  >  バックエンド開発  >  ランダム広告表示(PHP関数)_PHPチュートリアル

ランダム広告表示(PHP関数)_PHPチュートリアル

WBOY
WBOYオリジナル
2016-07-21 16:06:40834ブラウズ

#########ランダムな広告表示##########
function myads(){
$dir="ads"; #レコードが保存されるディレクトリを設定します
// $dir="ads"; #レコードが保存されるディレクトリを設定します
$ads="$dir/ads.txt"; #広告コードファイルを設定します
$log ="$dir/ads.log"; ip レコード ファイル

$ads_lines=file($ads);
$lines=count($ads_lines);#ファイル内の総行数

####広告の総数 $ads_count と配列 $display_array####### #
$ads_count=0;
for ($i=0;$i<$lines;$i++){
if((!strcmp (substr($ads_lines[$i],0,7 ;
}
####ランダムな表示シリアル番号を決定 $display_rand#####
srand((double)microtime()*1000000);
$display_rand = rand(1,$display_count);

###広告のシリアル番号を決定します$ ads_num######
$pricount=0;
for($i=1; $i< =$ads_count; $i++) {
$pricount += $display_array[$i];
if ($display_rand<=$pricount) {$ads_num=$i;break;}
}

###Play広告コード#########
$num=0;
$flag =0;

for($i<$lines;$i++){
if((!strcmp(substr) ($ads_lines[$i],0,7),"表示"))){ $num++;}
if(($num==$ads_num)and($flag==0)){$flag=1;続行;}
if(($flag==1)and strcmp($ads_lines[$ i][0],"#")){echo $ads_lines[$i];続行;}
if(($flag= =1)and(!(strcmp($ads_lines[$i][0]," #")))){break;}
}
####広告の表示回数を記録します###### ###
$fp=fopen($log,"a");
fputs($fp, date( "Y-m-d H:i:s " ).getenv("REMOTE_ADDR")."==>".$ ads_num."n");
fclose($fp);
}
?>

広告コード ファイル ads.txt

######## 各広告コードを「#」で区切ります。重み付けされた数値を表示します。数値が大きいほど、表示される回数が増えます ########## ######
################# ############
display=10

;img src="http://china.chance2mail.com/images/banner/c_banner.gif" alt="Chance2mail、素晴らしい贈り物です! ">
#############################
display=10


ショッピングのため My8848 ウェブサイトへようこそ



電話



http://www.bkjia.com/PHPjc/315413.html

www.bkjia.com

tru​​e

http://www.bkjia.com/PHPjc/315413.html技術記事 ?php #########ランダム広告表示########## function myads(){ $dir=ads;#レコードが保存されるディレクトリを設定 //$dir=ads;#ストレージを設定 記録ディレクトリ $ads=$dir/ads.txt; #広告コードファイルを設定...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。