twitter 分享链接

您所在的位置:网站首页 推特如何复制主页链接 twitter 分享链接

twitter 分享链接

2024-07-14 20:17| 来源: 网络整理| 查看: 265

twitter 分享链接

click here. 请单击此处 。

So, you want to display your Twitter status on your blog? No problem, use the API. But, what if you want to display links in your status like twitter.com itself does? No problem, use regular expressions.

那么,您想在博客上显示Twitter状态吗? 没问题,请使用API​​。 但是,如果您想像Twitter.com本身那样以状态显示链接怎么办? 没问题,使用正则表达式。

Here is a function that will turn all HTTP URLs, Twitter @usernames, and #tags into links:

这是一个将所有HTTP URL,Twitter @usernames和#tags转换为链接的函数:

PHP (The PHP) function linkify_twitter_status($status_text) { // linkify URLs $status_text = preg_replace( '/(https?:\/\/\S+)/', '\1', $status_text ); // linkify twitter users $status_text = preg_replace( '/(^|\s)@(\w+)/', '\1@\2', $status_text ); // linkify tags $status_text = preg_replace( '/(^|\s)#(\w+)/', '\1#\2', $status_text ); return $status_text; } 使用它 (Using It)

There are many ways to grab statuses from Twitter. Here, I will show a very simple method with no caching -- suitable for demonstration purposes. Feel free to substitute your favorite Twitter-fetching method.

有很多方法可以从Twitter获取状态。 在这里,我将展示一个没有缓存的非常简单的方法-适用于演示目的。 随意替换您最喜欢的Twitter提取方法。

$url = 'http://twitter.com/statuses/user_timeline/davidwalshblog.json?count=1'; $json = file_get_contents($url); $statuses = json_decode($json); $status_text = $statuses[0]->text; echo "before: ", $status_text, "\n"; echo "after: ", linkify_twitter_status($status_text), "\n";

The above code turns:

上面的代码变成:

@davidwalshblog: Check it out http://is.gd/hd2D #awesome ..into: @davidwalshblog: Check it out http://is.gd/hd2D #awesome

Pretty simple, eh?

很简单,是吗?

关于杰里米·帕里什(Jeremy Parrish) (About Jeremy Parrish)

Jeremy Parrish is the Systems Administrator for Econoprint, a print/design/web company in Verona, Wisconsin. He has a BS in Computer Engineering and Computer Science from the University of Wisconsin--Madison. In his spare time he enjoys running marathons with his wife and working on various coding projects. You can check out Jeremy's blog at http://rrish.org/.

杰里米·帕里什(Jeremy Parrish)是威斯康星州维罗纳市一家印刷/设计/网络公司Econoprint的系统管理员。 他拥有威斯康星大学麦迪逊分校的计算机工程和计算机科学学士学位。 在业余时间,他喜欢与妻子进行马拉松比赛并从事各种编码项目。 您可以在http://rrish.org/上查看Jeremy的博客。

翻译自: https://davidwalsh.name/linkify-twitter-feed

twitter 分享链接



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3