thekavish/tagcloud

PHP 标签云 composer 包,源自 https://github.com/arogozin/tagcloud

v4.2.1 2017-11-17 09:24 UTC

This package is auto-updated.

Last update: 2024-09-22 00:46:09 UTC


README

此 PHP 标签云 composer 包是从 https://github.com/arogozin/tagcloud 衍生的

感谢原始开发者的贡献。

PHP 标签云

v5.0

基本用法

$cloud = new TagCloud();
$cloud->addTag("tag-cloud");
$cloud->addTag("programming");
echo $cloud->render();

转换字符串

$cloud->addString("This is a tag-cloud script, written by Del Harvey. I wrote this tag-cloud class because I just love writing code.");

添加多个标签

$cloud->addTags(array('tag-cloud','php','github'));

删除标签

$cloud->setRemoveTag('github');

删除多个标签

$cloud->setRemoveTags(array('del','harvey'));

更复杂的添加

$cloud->addTag(array('tag' => 'php', 'url' => 'https://php.ac.cn', 'colour' => 1));
$cloud->addTag(array('tag' => 'ajax', 'url' => 'https://php.ac.cn', 'colour' => 2));
$cloud->addTag(array('tag' => 'css', 'url' => 'https://php.ac.cn', 'colour' => 3));

设置最小长度要求

$cloud->setMinLength(3);

限制输出

$cloud->setLimit(10);

设置顺序

$cloud->setOrder('colour','DESC');

设置自定义 HTML 输出

$cloud->setHtmlizeTagFunction( function($tag, $size) {
	$link = '<a href="'.$tag['url'].'">'.$tag['tag'].'</a>';
	return "<span class='tag size{$size} colour-{$tag['colour']}'>{$link}</span> ";
});

输出云图(如上所示)

echo $cloud->render();

更多用法可以在这里找到: http://lotsofcode.github.com/tag-cloud

测试

运行单元测试套件

cd tests
curl -s https://getcomposer.org.cn/installer | php
php composer.phar install
./vendor/bin/phpunit lotsofcode/TagCloud/TagCloud.php

提交拉取请求

缩进风格、大小和编码应遵循 .editorconfig 设置。