【发布时间】:2013-12-24 03:15:08
【问题描述】:
我正在从推文中提取网址:
示例 twitts 是:
\'Whn I ws calld for ths song @VishalDadlani @5hekhar both said \"we finally hv the perfect song for u\" lulz http://t.co/6vzbyjfCGk #DramaQueen\'
\'#FreeSunder @PMOIndia The world watches as India allows the torture of temple elephants to continue. PLEASE SHARE http://t.co/g8f1kgdasU\'
india
我想从所有此类用户推文中获取 tinyurl
我的代码:
<?php
$reg_exUrl = "/(?<![\>https?:\/\/|href=\"'])(?<http>(https?:[\/][\/]|www\.)([a-z]|[A-Z]|[0-9]|[\/.]|[~])*)/";
// The Text you want to filter for urls
$text = "Whn I ws calld for ths song lulz http://t.co/6vzbyjfCGk #DramaQueen\ ";
// Check if there is a url in the text
if(preg_match($reg_exUrl, $text, $url))
{
echo preg_replace($reg_exUrl, "<a href='{$url[0]}'>{$url[0]}</a> ", $text);
} else { // if no urls in the text just return the text
echo $text;
}
echo here 仅打印实际推文
这仅给出一个 url ,我如何从推文中获取所有 url?
【问题讨论】:
-
@Sim0n222:它给出了结果
Whn I ws calld for ths song lulz http://t.co/6vzbyjfCGk #DramaQueen\对吗?结果我只想要 url -
我再次更新了我的答案:)