james2doyle/parsetweet

此函数可以解析推文,并将@提及、#标签和URL包裹在链接标签中。

1.0.0 2016-05-13 19:22 UTC

This package is auto-updated.

Last update: 2024-09-21 19:52:40 UTC


README

此包将一个名为 parse_tweet 的单一函数添加到您的项目中。它只做一件事。解析推文。

此函数可以解析@提及、#标签和URL。所有链接都给予 target="_blank" 和适当的标题。

安装

在项目根目录下放置一个名为 composer.json 的文件,包含您的项目依赖项

{
    "require": {
        "james2doyle/parsetweet": ">=1.0"
    }
}

或使用 composer require james2doyle/parsetweet

示例

以下是一些示例输出

"This is a simple link https://google.com" == "This is a simple link <a href="https://google.com" target="_blank">https://google.com</a>"

"This is a simple mention for @james2doyle" == "This is a simple mention for <a title="@james2doyle" href="http://twitter.com/james2doyle" target="_blank">@james2doyle</a>"

"This is a simple #hashtag" == "This is a simple <a title="#hashtag" href="https://twitter.com/search?q=%23hashtag&src=hash" target="_blank">#hashtag</a>"

"This #weather is crazy! @weatherchannel" == "This <a title="#weather" href="https://twitter.com/search?q=%23weather&src=hash" target="_blank">#weather</a> is crazy! <a title="@weatherchannel" href="http://twitter.com/weatherchannel" target="_blank">@weatherchannel</a>"

"@james2doyle you need to visit https://warpaintmedia.ca because it is #cool!" == "<a title="@james2doyle" href="http://twitter.com/james2doyle" target="_blank">@james2doyle</a> you need to visit <a href="https://warpaintmedia.ca" target="_blank">https://warpaintmedia.ca</a> because it is <a title="#cool" href="https://twitter.com/search?q=%23cool&src=hash" target="_blank">#cool</a>!"

运行测试

进入项目根目录并运行 phpunit

许可证

MIT许可证

版权所有 (c) 2014 James Doyle james2doyle@gmail.com

在此条件下,免费授予任何获得此软件及其相关文档副本(“软件”)的人使用软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许向软件提供的人以本许可条件所规定的相同方式使用软件

上述版权声明和本许可声明应包含在软件的任何副本或主要部分中。

软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、特定用途的适用性和非侵权性。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论此类索赔、损害或其他责任是由于合同、侵权或其他方式引起的,无论与软件或软件的使用或其他方式有何关联。