Just change your first preg_replace to:
$status_text = preg_replace('~(https?://(\S+))~','<a href="$1">$2</a>',$status_text);
Frage
I have this code:
public function linkify($status_text)
{
$status_text = preg_replace('/(https?:\/\/\S+)/','<a href="\1">\1</a>', $status_text);
$status_text = preg_replace('/(^|\s)@(\w+)/','\1<a href="http://twitter.com/\2">@\2</a>',$status_text);
$status_text = preg_replace('/(^|\s)#(\w+)/','\1#<a href="http://search.twitter.com/search?q=%23\2">\2</a>',$status_text);
return $status_text;
}
and display feeds from twitter like this
foreach($feed as $feed_item) {
$html .= '<li>';
$html .= '' . $this->linkify($feed_item->text) . '';
$html .= '' . $this->relativedate((strtotime($feed_item->created_at))) . '';
$html .= '</li>';
}
echo $html;
result of this code is
<li>Twitter Feed Text <a href="http://t.co/TnkNfxCdRu">http://t.co/TnkNfxCdRu</a></li>
if anyone can help me, how can I add text inside tag <a></a>
. for example, to be exactly like this:
<li><a href="http://t.co/TnkNfxCdRu">Twitter Feed Text</a></li>
Thank you so much
Lösung
Just change your first preg_replace to:
$status_text = preg_replace('~(https?://(\S+))~','<a href="$1">$2</a>',$status_text);