Home  >  Article  >  Backend Development  >  Colorful label effect code sharing implemented in PHP, label code implemented in PHP_PHP tutorial

Colorful label effect code sharing implemented in PHP, label code implemented in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:20:221060browse

Sharing of colorful label effect code implemented in PHP, label code implemented in PHP

Currently, everyone usually adds a beautiful colorful mark on the left side of their blog, and I would like to add this small feature to my own website.

Unfortunately, it is no longer as convenient as when using WordPress. Friends who use WordPress can directly use ready-made plug-ins and add this dazzling function with just a click of the mouse. The small station program is written by myself. If you want to add such a function, you still have to do it yourself, so just think of it as learning!

First of all, I analyzed the main manifestations of colorful labels at present. There are two main points: various colors and different sizes. This is the characteristic of colorful tags, so I thought of the random function rand in PHP. Just give the size directly and use rand to randomly select the color.

Random values ​​of sizes are easy to get, just generate them directly and connect the units

Copy code The code is as follows:

// Random size instance
$m = rand(20,30);
echo 'random size';
?>

Generating color values ​​is a little more troublesome, because color values ​​are expressed in hexadecimal characters, and the random function rand cannot directly generate 0 to F. In the end, the hexadecimal characters are directly saved in an array, and then the mouse subscript is randomly generated like this Random colors can also be achieved
Copy code The code is as follows:

// Random color function
// Directly return the randomly generated color value
function getColor(){
​​​​ // First use an array to save the hexadecimal characters 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 is 6 bits long, it loops 6 times
for($i=0;$i<6;$i++){
                               // Randomly generate numbers from 0 to 15, and then use them as array subscripts to get values ​​
$color .= $arr[rand(0,15)];
}

              // When returning, add the # sign
Return ‘#’.$color;
}
?>

Once the random size and random colors are done, the rest is no longer a problem. Just take out all the tags and remove the duplicates, then traverse the array to generate HTML text.

Finally, some suggestions. After all, PHP is a server-side, and running rand every time will make the server lose weight (those particularly powerful machines can be ignored, after all, there are still many people using VPS). We can regenerate the tags of the blog when they change, such as deleting, modifying, or adding new tags to the blog, and then generate the HTML text of the colorful tags. In the end, the generated colorful HTML does not need to be stored in the database. It can be saved directly in a file and then included.

Currently, this is how my website is implemented. When I have time, I will introduce JavaScript to implement colorful tags. The principle is almost the same, except that JavaScript is a client-side behavior, so you don’t have to worry about server-side problems. Moreover, JavaScript is relatively interactive and can create cloud tags with animated effects.

Who has the php code to achieve the slide effect on the web page?

That is the effect of js+html tag+css or js+flash.
Baidu the code. If it is not easy to use or not suitable, please improve it yourself!
What others give you is actually not perfect for you, because it is not specially made for you. . . . .
Of course you have to change it to suit you according to your own needs. . . . .

How to use javascript to add PHP code to the DIV tag of a web page?

This is impossible. PHP is executed before the page is generated, while javascript is executed after it is generated. You can't actually see the include.... PHP code in the page you open with your browser. What you see is the result after PHP execution.
There are two ways to achieve what you said:
One is to create a separate page to include 2.php, and then go directly to this new page where outmsg() is executed.
The second is to add a parameter to the current page, use $_REQUEST['parameter name'] to obtain it in PHP, and then use if to judge. If there is a parameter, include 2.php, otherwise include 1.php. When executing outmsg() on the current page, submit a form to the current page and add this parameter.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/867249.htmlTechArticle Sharing of colorful tag effect code implemented by PHP, PHP tag code currently, everyone usually adds a on the left side of their blog Beautiful colorful markers, I also want to add this feature to my website...
Statement:
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