In my database, users enter a string of text that could contain a url to some website. Right now I am just outputting that website and the url must be copy and pasted. I am trying to replace that url (if there is one) and convert it to an html anchor tag if there is one.
So far I loop thru every record and replace that text if there is a url in there. (I also want to keep any text they type in around that url.) This is the function I use for that:
foreach ($applications as $a) {
$web = $a->websites;
$web = preg_replace('~(\s|^)(https?://.+?)(\s|$)~im', '$1<a href="$2" target="_blank">$2</a>$3', $web);
$web = preg_replace('~(\s|^)(www\..+?)(\s|$)~im', '$1<a href="http://$2" target="_blank">$2</a>$3', $web);
$a->websites = nl2br($web);
}
If I echo and die in the Controller, it properly outputs the text and url with an anchor tag. However in my blade output I do this:
@foreach ($applications as $application)
<tr>
<td>{{{ $application->websites or '' }}}</td>
</td>
</tr>
@endforeach
This is outputting like this though:
<a href="http://ift.tt/1OCigZY" target="_blank">http://ift.tt/1LMD3ES;
(The website link is not being linkifyed, it is just a string.)
Wondering if anyone has any solutions for this.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire