将Twitter状态上的链接转换为可单击的url。加@和#
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将Twitter状态上的链接转换为可单击的url。加@和#相关的知识,希望对你有一定的参考价值。
To convert links on a twitter status to a clickable url. Also convert @ to follow link, and # to search
/** * * twitterStatusUrlConverter * * To convert links on a twitter status to a clickable url. Also convert @ to follow link, and # to search * * @author: Mardix - http://mardix.wordpress.com, http://www.givemebeats.net * @date: March 16 2009 * @license: LGPL (I don't care, it's free lol) * * @param string : the status * @param bool : true|false, allow target _blank * @param int : to truncate a link to max length * @return String * * */ function twitterStatusUrlConverter($status,$targetBlank=true,$linkMaxLen=250){ // The target $target=$targetBlank ? " target="_blank" " : ""; // convert link to url ]+)/e", "'<a href="$1" title="$1" $target >'. ((strlen('$1')>=$linkMaxLen ? substr('$1',0,$linkMaxLen).'...':'$1')).'</a>'", $status); // convert @ to follow $status = preg_replace("/(@([_a-z0-9-]+))/i","<a href="http://twitter.com/$2" title="Follow $2" $target >$1</a>",$status); // convert # to search $status = preg_replace("/(#([_a-z0-9-]+))/i","<a href="http://search.twitter.com/search?q=%23$2" title="Search $1" $target >$1</a>",$status); // return the status return $status; }
以上是关于将Twitter状态上的链接转换为可单击的url。加@和#的主要内容,如果未能解决你的问题,请参考以下文章