Author: LuciferStar Source: Beyond PHP Preface: Now, more and more people like to go online, and more and more people have their own personal homepages. With the emergence of various automated software tools, making web pages is becoming easier and easier. However, since special effects are widely available, there are fewer and fewer innovative things. Maybe, one day, you will find that the counter on a website is exactly the same as yours. The web page is becoming more and more mature. There are more and more things on the web, and they are becoming richer and richer. Question: On a web page, if I want to add a counter: In the past, I would go to the space provider and ask for a link, or copy the address from other places, but these are always done by others, okay? Those who don’t have much say can only find them one by one. On the web page, I want to publish some information: If the information is text, create a new page and add a link; if it is data, create a new page and add a link: But if the data is updated frequently, even every hour, It may change every minute. Are you willing to stay in front of the computer, constantly modifying and uploading? (We are not a commercial website, no one is willing to spend money for you.) Message boards, chat rooms, forums, these cannot be accomplished by HTML and JAVASCRIPT alone. In order to achieve more automatic control, CGI (Common Gateway Interface) programs can be used to implement these functions. Software requirements: PHP: GD Library configures a server that supports PHP. I use OmniHTTPd Professional for counters and real-time data statistics and publishing, which we can do with images. Output text in the picture. In PHP, to create a picture and display point content on it, the basic steps are as follows: In the above example, on a 400×300 picture, starting from point (10, 10), draw a 12-point "1234567890" . Did you notice that the size of this image is: 251 bytes! You can also try other output formats. The size of the picture is related to the number of non-background pixels in the picture, and has nothing to do with how many pixels are output. However, there is a problem. You can use imagestring() to output the following information: imagestring($im,1,0,0,"abcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_+{}|:"?[];, ./",$red); However, you cannot output Chinese correctly!!! imagestring($im,1,0,0,"Ah",$red); What you see is definitely not Chinese!! But garbled characters . The default character set of PHP is UTF-8, and Simplified Chinese is GB2312. How to solve this problem? In order to solve this problem, you can let PHP load the extension module php_iconv.dll (the suffix name under UNIT is .SO). Sometimes, it may not work properly. Originally, I was going to put a piece of test code, but this time, it didn't work. In order to avoid errors, I didn't put them up. But the most fatal thing is that if your If the space service provider closes the extension module, or even disables the DL() function of the loading module, then you can only BYE-BYE with Chinese. Fortunately, there are other ways to pre-install it through character mapping. The characters in the converted code table are output. But, you need a code table! How about drawing every point of the Chinese characters by hand? Okay, let’s draw the characters together! First of all, you need to know how to draw. Have you learned about simple functions in junior high school? Have you ever done this? Calculate the coordinates of a certain point and then connect two adjacent points. This method is called the point drawing method. It is to calculate as many points as possible and then display them at the corresponding coordinates. Have you ever heard of dot matrix printers and dot matrix Chinese characters? When outputting Chinese characters, they are represented by points at a certain coordinate. The function to display a point of a certain color is: int imagesetpixel (resource image, int x, int y, int color) Suppose I want to display a white point at coordinates (100,100), then, I only need the following code: In other words, as long as we obtain the information of all points of a certain Chinese character, we can output that Chinese character through this function.In the file chs16.fon, what is saved is the national standard location code table (national standard Chinese character encoding basic character set for information exchange GB-2312). It is a dot matrix font library for Chinese characters. (In WIN98 system, this file is under c:windowscommand. If you want to use it under UNIX system, please pay attention to the case. If not, you can find the link at the end of the article.) It is from the MSDOS era, but, well Things should still be taken out and used. From chs16.fon, we can read the lattice data of Chinese characters. Each Chinese character is composed of 16×16 dots. Where the stroke passes, the value of the point is 1, otherwise it is 0; each point occupies one bit, and every 8 points constitute a byte. Then, a Chinese character requires (16×16÷8=32) bytes. The following example is to illustrate the representation method of character dot matrix. Here, an 8×8 matrix is defined, showing a letter C. The white square is represented by 0, and the black square is represented by 1. Then, the codes of these eight lines of graphics are: Line binary represents hexadecimal represents 0 00000000 0x00 1 00111110 0x3E 2 01110000 0xE0 3 01110000 0xE0 4 01110000 0xE0 5 01110000 0xE0 6 00111110 0x3E 7 00000000 0 x00 To output these points, you need to draw the first line first, then the second line, the third line... to the last line . Use a loop: for($hang=0;$hang "location code" to index and search. As mentioned before, a Chinese character takes up 32 bytes in the table, so we define a character containing 32 Array of elements: $buffer=array(0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0 ,0,0,0,0, 0,0,0,0,0, 0,0); used to save the 32-byte data read from the font library. The next question is, where is a certain character stored? Where in the file? Since a Chinese character uses 32 bytes, and the GB-2312 area code table has 94 rows and 94 columns, then, as long as you know the number of the character in the table, then multiply by 32. . So define the offset: $offset=(94*($qh-1)+($wh-1))*32; $qh represents the area (qu), $wh represents the bit (wei); minus 1, This is because PHP starts counting from 0. To find the position, you only need to use the fseek() function to set the position in the code table, and then read 32 bytes into $buffer. In addition, since Chinese is composed of two bytes. The dot matrix example given earlier is 8 bits, one byte, so the code for drawing dots needs to be modified: for($hang=0;$hang