PHP implements the colorful tag effect code sharing and php implements the tag code

Source: Internet
Author: User
Tags pears

PHP implements the colorful tag effect code sharing and php implements the tag code

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.
Copy codeThe Code is as follows:
<? Php
// Random size instance
$ M = rand (20, 30 );
Echo '<span style = "font-size:'. $ m. 'px"> random size </span> ';
?>
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.
Copy codeThe 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 <? Include... the PHP code shows the result after PHP Execution.
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.