PHP implements the colorful tag effect code sharing and php implements the tag code. The colorful tag effect code implemented by PHP is shared. Currently, the tag code implemented by php is usually marked with a colorful tag on the left side of your blog, I also want to add the colorful tag effects of PHP to my website and share the tag code of php.
Currently, the left side of a blog is usually filled with a colorful tag, and you want to add this feature to your website.
Unfortunately, it is no longer so convenient to use WordPress. friends who use WordPress can directly use the ready-made plug-in to add this colorful function with a click. The station program is self-written. if you want to add such a function, you have to do it on your own. just learn it!
First, I analyzed the main manifestations of the current colorful labels, mainly including two aspects: different colors, different sizes. This is a colorful tag feature, so I thought of the random function rand in PHP. Directly give the size, the color can be random value with rand.
The random value of the size is easy to handle. the unit can be directly generated and connected.
The code is as follows:
<? Php
// Random size instance
$ M = rand (20, 30 );
Echo 'random size ';
?>
It is a little complicated to generate a color value because the color value is a hexadecimal character representation, and the random function rand cannot directly generate 0 to F, finally, the hexadecimal characters are saved directly with arrays, and the mouse subscript is randomly generated. This can also achieve random color.
The code is as follows:
<? Php
// Random color function
// Directly return the random color value
Function getColor (){
// First use an array to save the hexadecimal character in an array
$ Arr = array ('0', '1', '2', '3', '4', '5', '6', '7 ', '8', '9', 'A', 'B', 'C', 'D', 'e', 'F ');
// Because the color value length is 6 bits, the cycle is 6 times.
For ($ I = 0; $ I <6; $ I ++ ){
// Generate 0-15 numbers randomly and use them as array subscript values.
$ Color. = $ arr [rand (0, 15)];
}
// Add # to the returned result
Return '#'. $ color;
}
?>
Random size and random color are not a problem. Remove all tags and traverse the array to generate HTML text.
Finally, we suggest that, after all, PHP is the server side. every time rand is used, it will make the server a lot of pears (the special machines can be ignored, after all, there are still a lot of VPS ). We can generate a blog tag when it changes, such as deleting, modifying, and adding a new tag to an article. then, we can generate HTML text with colorful tags. Finally, these colorful HTML tags do not need to be stored in the database, stored directly in a file, and then include.
At present, my small station is implemented in this way. When I have time, I will introduce JavaScript to implement colorful tags. The principle is similar, but JavaScript is a client-side behavior, so I don't have to worry about the server-side pears, and the JavaScript interaction is better, you can create cloud labels with animation effects.
Who has php code for implementing slide on the webpage?
That is the effect of js + html tag + css or js + flash,
The code is baidu. it is not easy to use or suitable for use. please try again!
What others give you is not perfect for you, because it is not born for you .....
Then, of course, you need to change it to a suitable one according to your own needs .....
How to use javascript to add PHP code to the DIV tag of a webpage?
This is impossible. PHP is executed before the page is generated, while javascript is executed after the page is generated. The page you opened in a browser is actually invisible. There are two ways to achieve this:
First, create a separate page to include 2.php, and then directly go to the new page where outmsg () is executed.
Second, add a parameter to the current page. in PHP, use $ _ REQUEST ['parameter name'] to obtain the parameter, and then use if to judge. if there is a parameter, include 2.php; otherwise, include 1.php. When outmsg () is executed on the current page, it is submitted to the current page using a form. this parameter is added.
At present, the left side of a blog is usually filled with a colorful mark, and I want to add this trick to my website...