I am currently using the EpiTwitter API to grab Tweets and store them in the database however I want to replace any 'T.co' links in a given tweet and replace them with the full links. The regex is where I need a bit of help for determining how to replace the link.
Twitter returns the URL's via the urls
entity.
"urls": [{
"url": "https:\/\/t.co\/XdXRudPXH5",
"expanded_url": "https:\/\/blog.twitter.com\/2013\/rich-photo-experience-now-in-embedded-tweets-3",
"display_url": "blog.twitter.com\/2013\/rich-phot\u2026",
"indices": [80, 103]
}],
I am currently calling the API and looping through the tweets like so:
$resp = $twitterObj->get('/statuses/user_timeline.json', array('screen_name'=>$row['screenname']));
foreach($resp->response as $tweet)
{
foreach($tweet['entities']['urls'] as $url_type)
{
if(preg_match('/https:\/\/t.co\/[^\s]+/', $url_type['url']))
{
$processedtweet = str_replace($url_type['url'], $url_type['expanded_url'], $tweet['text']);
}
}
}
The regex for checking it is a T.co link and replacing it with that links expanded_url
or display_url
entity is where I need help as the preg_match statement isn't evaluating the T.co link correctly.
Edit
I tested this with the link: https://t.co/XdXRudPXH5
and it evaluates correctly however the twitter API shows it with the backslashes throughout the link. Will they be required by the time my code comes around to reading the url? Basically will my regex have to take all the backslashes into account.
Thanks.