How do I detect and display url links from standard text?
I'm currently following L6-from-Scratch series, in particular the Tweet app.
The app uses standard html form for text input, then displays this further down the page (like Twitter).
Question...
If I "tweet" some text which also contains a url, how can I display and make active and url link contained within it?
you can use this function to do what you want wit JS
function linkify(text) {
var urlRegex =/(\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~|!:,.;]*[-A-Z0-9+&@#/%=~|])/ig;
return text.replace(urlRegex, function(url) {
return '' + url + '';
});
}
or with PHP you can see this link https://gist.github.com/jasny/2000705
Hey T, I was looking further into Autolinker, and have imported the js into my project.
The part I want autolinker working on is a string table output (named 'body') which is being output from a blade template (below):
{{ $tweet->body }}
I'm guessing I just need to apply the autolinker to this "body" property, but i've got no idea how to do it.