Use PHP to write a label based on the font size and color display by click rate-PHP source code

Source: Internet
Author: User
Ec (2); set the font size and color of the tag according to the click rate of the tag. This program does not consider program performance and function encapsulation... The code for expressing this algorithm is as follows: & nbsp; & lt ;? Php & nbsp; function & nbsp; showTag ($ cur47, $ tag & quot; beauty & quot;) {& nbsp; & nbsp; & nbs script ec (2); script

Set the font size and color of a tag Based on the click rate of the tag.

This program does not consider program performance and function encapsulation... Just want to express this algorithm

The Code is as follows:



Function showTag ($ cur = 47, $ tag = "Beauty and the Beast "){
$ MaxSize = 300; $ minSize = 30; // maxSize indicates the maximum label font size, and minSize indicates the minimum label size.
$ Max = 100; $ min = 8; // max indicates the maximum number of tag clicks. min indicates the minimum number of clicks. cur indicates the current tag clicks.
$ TagColor = $ tagSize = $ minSize; # tagColor indicates the final color of the tag, and tagsize indicates the final font size of the tag.
$ TagSize = @ (float) ($ cur-$ min)/($ max-$ min) * ($ maxSize-$ minSize );

$ Colors = array ("0.2" => "#333333", "0.4" => "# 0033CC", "0.6" => "#660099 ", "0.8" => "#00 FFFF", "1" => "# FF0000 ");
// Color is an array of colors, which can be characters in length, for example, color1 between 0-0.2.
$ Colorkeys = array_keys ($ colors );

$ Select = (float) ($ cur-$ min)/($ max-$ min );
$ Len = count ($ colorkeys );
$ I = 0; $ j = $ len-1;
While ($ I <$ j) {// Binary Search
$ Index = ($ I + $ j)/2;
If ($ select >=( float) $ colorkeys [$ index] & $ select <(float) $ colorkeys [$ index + 1]) break;
Elseif ($ select <(float) $ colorkeys [$ index]) $ j --;
Elseif ($ select> (float) $ colorkeys [$ index]) $ I ++;
Elseif ($ select = (float) $ colorkeys [$ index + 1]) break;
Else break;
}
$ TagColor = $ colors [$ colorkeys {($ I + $ j)/2}];
Echo "$ tag ";
}
ShowTag (90); showTag (66, "stockholders"); showTag (50, "My hobbies"); showTag (100, "MM ");
?>


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.