【发布时间】:2017-01-01 00:49:49
【问题描述】:
我正在尝试在带有此正则表达式 #^https?://twitter\.com/(?:\#!/)?(\w+)/status(es)?/(\d+)$#is 的消息中获取推文 URL(如果找到)
但我的正则表达式似乎不正确,无法获取推文 URL。以下是我的完整代码
function gettweet($string)
{
$regex = '#^https?://twitter\.com/(?:\#!/)?(\w+)/status(es)?/(\d+)$#is';
$string = preg_replace_callback($regex, function($matches) {
$user = $matches[2];
$statusid = $matches[3];
$url = "https://twitter.com/$user/status/$statusid";
$urlen = urlencode($url);
$getcon = file_get_contents("https://publish.twitter.com/oembed?url=$urlen");
$con = json_decode($getcon, true);
$tweet_html = $con["html"];
return $tweet_html;
}, $string);
return $string;
}
$message="This is absolutely trending can you also see it here https://twitter.com/itslifeme/status/765268556133064704 i like it";
$mes=gettweet($message);
echo $mes;
【问题讨论】: