Pregunta

I have a twitter feed at the bottom of my website I am in the process of building: http://matthewkcooper.netii.net/

As you can see it is outputting url links at hashtags that are not clickable. How can I make these links active?

¿Fue útil?

Solución

I found an autolink function from Why does this function not autolink? and added it near the bottom of the script you linked to, calling it around $row['desc'] in the echo.

function twitterify($ret)
{
    $ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
    $ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
    $ret = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $ret);
    $ret = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=%23\\1\" target=\"_blank\">#\\1</a>", $ret);
    return $ret;
}

foreach($feed as $row)
{
    echo('<div>'.twitterify($row['desc']).'<span><a href="'.$row['link'].'">'.relativedate(time()-strtotime($row['date'])).' ago</a></span></div>');
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top