hpolthof / tagcloud
PHP Tag Cloud composer 包实现了 http://lotsofcode.github.io/tag-cloud/
v4.0.2
2015-07-07 10:24 UTC
Requires
- php: >=5.4.0
- illuminate/support: ~5
This package is auto-updated.
Last update: 2024-09-11 03:44:18 UTC
README
PHP Tag Cloud composer 包实现了 http://lotsofcode.github.io/tag-cloud/
PHP Tag Cloud
v4.0
安装
使用 composer
composer require hpolthof/tagcloud
基本用法
$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/installer | php
php composer.phar install
./vendor/bin/phpunit lotsofcode/TagCloud/TagCloud.php
提交拉取请求
缩进风格、大小和编码应遵循 .editorconfig 设置。