Home > Backend Development > PHP Tutorial > Put counter and calendar in *.htm or *.html file_PHP tutorial

Put counter and calendar in *.htm or *.html file_PHP tutorial

WBOY
Release: 2016-07-13 17:24:39
Original
997 people have browsed it

Generally, the text counter or calendar you make must be placed in a *.PHP file. If you must use htm or html as the file extension (such as index.html), can you still put the counter or calendar? The answer is yes. The method is to first use PHP's graphics output function to draw the desired graphics, and then use the HTTP header information to enable the html file to process the PHP file as a graphics file. Put a counter or Calendar becomes as easy as placing a picture file! The following is the PHP source code of the counter graphic file count.php and the calendar file date.php:

---------------File count.php (counter)--- -------

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);
fclose($fp);

$strCount = strval ($Count); //The obtained count is converted into a string
$strCount = Chop($strCount);
$CountLen = strlen($strCount);

for($i = 0; $i $strCount = "0".$strCount;

//Create a graph Like
$img = imagecreate(90, 26);

//Matching color
$black = imagecolorallocate($img, 0, 0, 0);
$green = imagecolorallocate( $img, 0, 255, 0);


$fgray = imagecolorallocate($img, 180, 180, 180);
$dgray = imagecolorallocate($img, 130, 130, 130);
$gray = imagecolorallocate($img, 160, 160, 160);

//Draw the border
imagerectangle($img, 0, 0, 89, 25, $fgray);
imagerectangle($img, 1, 1, 88, 24, $dgray);
imagerectangle($img, 2, 2, 87, 23, $gray);

//Output count
imagestring($img, 4, 13, 5, $strCount, $green);

//Output image
header("Content-type:image/png");
imageinterlace( $img, 1);
imagepng($img);
?>


---------------File date.php (calendar )-------------------------------

//Create image
$img = imagecreate( 132, 26);

//Matching color
$black = imagecolorallocate($img, 0, 0, 0);
$green = imagecolorallocate($img, 0, 255, 0) ;
$fgray = imagecolorallocate($img, 180, 180, 180);
$dgray = imagecolorallocate($img, 130, 130, 130);
$gray = imagecolorallocate($img, 160, 160, 160);

//Draw the border
imagerectangle($img, 0, 0, 131, 25, $fgray);
imagerectangle($img, 1, 1, 130, 24 , $dgray);
imagerectangle($img, 2, 2, 129, 23, $gray);

//Output date
imagestring($img, 4, 11, 5, date ("Y.m.d.D"), $green);

//Output image
header("Content-type:image/png");
imageinterlace($img, 1);
imagepng($img);
?>

As long as you insert these two files as graphic files anywhere in the HTML file, they will become a counter and calendar. You can go to the following address to see the effect:
http://youziyun.oso.com.cn

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532133.htmlTechArticleGenerally, the text counter or calendar you make should be placed in a *.PHP file. If you must use htm or If I use html as a file extension (such as index.html), can I also put a counter or calendar? Reply...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template