PHP实现的多彩标签效果代码分享,php实现标签代码
PHP实现的多彩标签效果代码分享,php实现标签代码
目前,大家的博客左侧通常加上一个漂亮的多彩标记,也想给自己的小站加一下这个小功能。
可惜已经再不再是使用WordPress的时候那么方便了,使用WordPress的朋友们直接使用现成的插件,鼠标点点就可以加上这个炫彩的功能。小站程序是自个写的,要加这么一个功能还是得自己动手,就当学习吧!
首先,我分析了一下目前多彩标签的主要表现形式,主要有两点:颜色多样,大小不一。这个是多彩标签的特性,于是想到了PHP中的随机函数rand。直接给大小,颜色用rand随机取值就可以。
大小的随机值容易搞定,直接生成后连接单位即可
复制代码 代码如下:
// 随机大小实例
$m = rand(20,30);
echo '随机大小';
?>
生成颜色值稍微麻烦一些,因为颜色值是十六进制字符表现形式,而随机函数rand不能直接生成 0 到 F 这么用,最后直接用数组保存十六进制字符,然后随机生成鼠标下标这样也可以实现随机颜色
复制代码 代码如下:
// 随机颜色函数
// 直接返回随机生成的色值
function getColor(){
// 先用数组把十六进制字符保存在一个数组中
$arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
// 因为颜色色值长度是6位,所以循环6次
for($i=0;$i
// 随机生成0到15数字,然后当作数组下标取值即可
$color .= $arr[rand(0,15)];
}
// 返回的时候,把#号加上
return ‘#'.$color;
}
?>
随机大小,随机颜色搞定后剩下的都不是问题的问题了。直接取出所有标签然后去重,然后遍历数组生成HTML文本即可。
最后提点建议,毕竟PHP是服务器端,每次都rand会让服务器鸭梨不小(那些特牛的机器可以忽略不计,毕竟目前用VPS的还是众多)。我们可以在博客的标签在发生变动的时候再生成即可,比如删除,修改,增加文章产生新的标签时候我们再去生成多彩标签的HTML文本。最后这些生成的多彩签HTML没必要存进数据库,直接保存在在一个文件里,然后include即可。
目前,我的小站就是这么实现的。有空,我再介绍JavaScript实现多彩标签,原理也差不多一样,只不过是JavaScript是客户端行为,不用担心服务器端的鸭梨,而且JavaScript交互性比较好,可以制作出具有动画效果的云标签。
那是js+html标签+css或者js+flash的效果,
代码百度一下,不好用或者不适合,自己再改进一下!
别人给你的其实都不是完美适合你,因为不是专门为你而生的。。。。。
那你当然要根据自己的需要改成适合自己的啊。。。。。
这种是不可能的。PHP是在生成页面之前执行,而javascript是在生成之后执得。你用浏览器打开的页面实际上是看不到 include.... 这些 PHP 代码的,看到的是PHP执行之后的结果。
要实现你说的这种有两个办法:
一是新建一个单独的页面,用来包括2.php,然后在执行outmsg()的地方直接转到这个新页面。
二是在当前这个页面上加一个参数,在PHP中用$_REQUEST['参数名字']来获取,再用if判断,如果有参数,则include 2.php,否则include 1.php。在当前的页面执行outmsg()的时候就用一个表单提交到当前页面,把这个参数加上。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
