Skip to content

Instantly share code, notes, and snippets.

@PhilKershaw
Last active December 29, 2015 00:19
Show Gist options
  • Save PhilKershaw/7585656 to your computer and use it in GitHub Desktop.
Save PhilKershaw/7585656 to your computer and use it in GitHub Desktop.
Wrap URLs in tweets in a tags.
<?php
private static function _applyEntities(&$feed)
{
if (null !== $feed) {
foreach($feed as &$item) {
if (null !== $item['entities']['urls']) {
$urls = array_reverse($item['entities']['urls']);
$content = &$item['text'];
foreach ($urls as $url) {
$content = substr_replace($content, '</a>', $url['indices'][1], 0);
$content = substr_replace($content, '<a href="'.$url['url'].'">', $url['indices'][0], 0);
}
unset($content);
}
}
unset($item);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment