PHP解析urlmailto和twitter™s用户名和参数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP解析urlmailto和twitter™s用户名和参数相关的知识,希望对你有一定的参考价值。
This small function receive a text as input and returns an html text with links if the source text contains urls (http://www… but also ftp://… and every other protocol), emails, twitter’s usernames (with @ at the beginning) and also twitter tags (with # at the beginning).
function parse_twitter($t) { // link URLs "([[:alnum:]#?/&=])/i", "<a href="\1\3\4" target="_blank">". "\1\3\4</a>", $t); // link mailtos "([[:alnum:]-]))/i", "<a href="mailto:\1">\1</a>", $t); //link twitter users $t = preg_replace( "/ [email protected]([a-z0-9_]*) ?/i", " <a href="http://twitter.com/\1" target="_blank">@\1</a> ", $t); //link twitter arguments $t = preg_replace( "/ +#([a-z0-9_]*) ?/i", " <a href="http://twitter.com/search?q=%23\1" target="_blank">#\1</a> ", $t); // truncates long urls that can cause display problems (optional) "{30,40})([^[:space:]]*)([^[:space:]]{10,20})([[:alnum:]#?/&=])". "</", ">\3...\5\6<", $t); }
以上是关于PHP解析urlmailto和twitter™s用户名和参数的主要内容,如果未能解决你的问题,请参考以下文章
Twitter-打印用户的最新tweet(摘自PHP中的RSS提要和linkifies链接)
在Wordpress中创建twitter小部件函数.php文件
无法使用 Twitter API、PHP 和 curl 发布图像和文本?媒体/上传和状态/更新