i-lateral/hashtagger
Composer 安装命令:
composer require i-lateral/hashtagger
包简介
Simple library for finding hashtags in string
README 文档
README
This is a simple class that is designed to extract hashtags from within a string.
Installation
The prefered way to run this is via composer:
# composer require i-lateral/hashtagger
Usage
First you must instantiate the HashTagger class:
use HashTagger\HashTagger
$string = "String with #hashtags";
$tagger = new HashTagger($string);
HashTagger will run an initial parsing of the provided string and cache the extracted tags, these can be accessed via:
$tagger->get_tags();
NOTE That each tag will be preceeded with the # symbol, EG:
var_dump($tagger->get_tags());
Outputs:
array(1) {
[0] =>
string(8) "#hashtag"
}
You can add or remove tags from the final list via the add_tag and remove_tag methods:
$tagger->remove_tag("#hashtag");
$tagger->add_tag("#newtag");
var_dump($tagger->get_tags());
Outputs:
array(1) {
[0] =>
string(8) "#newtag"
}
Wrapping/Converting tags into XML/HTML
You can convert tags in the string into HTML elements using the "wrap_tags" method.
Wrappping all tags in a strong element:
$new_string = $tagger->wrap_tags("strong");
You can also add custom attributes to these elements, EG wrapping all tags in a strong element with the class "hashtag":
$new_string = $tagger->wrap_tags(
"strong",
array("class" => "hashtag")
);
Finally, you can customise the attributes value to use the tag name (for example to build custom links) by adding the string {tag} to your attribute value, EG:
$new_string = $tagger->wrap_tags(
"a",
array("href" => "http://site.com/tag/{tag}")
);
The above will wrap the tag in an anchor element with a custom href specifically for that tag.
Future Development
This lib covers all the basic functionality, but it would be nice to tweak the wrapping method so that it ignores tags that have already been wrapped in an element.
i-lateral/hashtagger 适用场景与选型建议
i-lateral/hashtagger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 193 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 05 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「tagging」 「hashtag」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 i-lateral/hashtagger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 i-lateral/hashtagger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 i-lateral/hashtagger 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tags plugin for CakePHP
Replace hashtags with a link that search into Flarum
A patch for TYPO3 to easily add tags just like categories to any element
Unified API for key-value storages in memory. As a storage can be used: APC, Redis, Memcache, Couchbase or MongoDB. All storage objects have one interface, so you can switch them without changing the working code.
Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.
A simple php service for parsing hashtags from a string in any language.
统计信息
- 总下载量: 193
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Facebook
- 更新时间: 2016-05-11