通常、作成したテキスト カウンターまたはカレンダーは *.PHP ファイルに配置する必要があります。ファイル拡張子として htm または html を使用する必要がある場合でも、カウンターまたはカレンダーを配置できますか?答えは「はい」です。その方法は、まず PHP のグラフィックス出力機能を使用して目的のグラフィックスを描画し、次に HTTP ヘッダー情報を使用して PHP ファイルをグラフィックス ファイルとして処理できるようにすることで、画像を配置するのと同じくらい簡単にカウンターやカレンダーを配置できます。ファイル!以下は、カウンターグラフィックファイル count.php とカレンダーファイル date.php の PHP ソースコードです:
--------------ファイル count.php (カウンター)--- ---- ---
if(!file_exists("count.txt"))
exec("echo 0 > count.txt");
$fp = fopen("count.txt", "r+ ");
$FileSize = filesize("count.txt");
$Count = fgets($fp, $FileSize + 1);
$Count += 1;
fseek($fp, 0);
fputs($fp , $Count);
$strCount = strval($Count); //取得したカウントを文字列に変換します
$strCount = Chop($strCount); strlen($ strCount);
for($i = 0; $i $ strCount = "0".$strCount;
//画像を作成
$img = imagecreate(90, 26);
//カラーを一致させる
$black = imagecolorallocate($img, 0, 0, 0);緑 = imagecolorallocate($img, 0, 255 , 0);
$fgray = imagecolorallocate($img, 180, 180, 180); | $dgray = imagecolorallocate($img, 130, 130, 130) );
$gray = imagecolorallocate($img , 160, 160, 160);
//境界線を描画します
imagerectangle($img, 0, 0, 89, 25, $fgray); , 1, 88, 24, $dgray);
imagerectangle($img, 2, 2, 87, 23, $gray);
//出力数
imagestring($img, 4, 13, 5, $strCount, $green);
//出力画像
header("Content-type:image/png");
imagepng($img); ---------------------- -ファイル date.php (カレンダー)---------------------- ----------
//画像を作成
$img = imagecreate (132, 26);
//マッチングカラー
$black = imagecolorallocate($img, 0, 0, 0) ;
$green = imagecolorallocate($img, 0, 255, 0);
$fgray = imagecolorallocate($img, 180, 180, 180); $gray = imagecolorallocate($img, 160, 160, 160);
//境界線を描画します
imagerectangle ($img, 0, 0, 131, 25, $fgray); 130, 24, $dgray);
imagerectangle($img, 2, 2, 129, 23, $gray );
//出力日付
imagestring($img, 4, 11, 5, date("Y.m.d.D") , $green);
//出力画像
header("Content-type:image/png") ;
imagepng($img); この 2 つを挿入するだけです。ファイルを HTML ファイル内の任意の場所にグラフィック ファイルとして配置すると、カウンターとカレンダーになります。効果を確認するには、アドレスを確認してください:
http://youziyun.oso.com.cn
http://www.bkjia.com/PHPjc/532133.html
www.bkjia.com
本当
http://www.bkjia.com/PHPjc/532133.html
技術記事
通常、作成したテキスト カウンターまたはカレンダーは *.PHP ファイルに配置する必要があります。ファイル拡張子として htm または html を使用する必要がある場合でも、カウンターまたはカレンダーを配置できますか?に戻る...