Hi, I'm having a problem changing a text URL into a hyperlink in a given string. It works O.K, but messes up a little dependeing on the string. E.g. it could be www.example.com. note the . It worked for most as they didn't have the . in but this particular one is: www.example.com/page.<br /> I'm just a little unsure how to handle it as I can't remove the . in that instance because of .php. .html pages etc. Here is what I have so far: function addLinks($Text){ if (preg_match("/http/", "$Text") OR preg_match("/www/", "$Text")) { $Text = str_replace(" www" , " http://www" , $Text); $Explode = explode(" ", $Text); foreach($Explode as $Check) {if (preg_match("/http/", "$Check") OR preg_match("/www/", "$Check")) {$Text = str_replace($Check , "$Check" , $Text);}} } return $Text; } PHP: Found here: http://css-tricks.com/snippets/php/find-urls-in-text-make-links/#comment-133881 Any ideas on how to handle this? Thanks
I'm not really sure why you have to get rid of that trailing period? It has no impact on web-addresses (normally)? Besides, that function looks a bit... clunky. I'm assuming this is to add a simple http: before whatever link you have in your text which doesn't have this? And thereafter I'm assuming there's some other function which takes this http:-link and actually creates a link from it? (Like a built-in text-parser?)
Sorry I sent the wrong snippet. I have multiple people uploading news stories, they're copy and pasted in from edits and there's not enough time for them to add hyperlinks, so I thought about putting a function in there to handle them. Problem is, they're not consistent. Some will have http:// others simply have www. or have a full stop after them. Here's an example: But in the HTML it looks like: Apprenticeship vacancies can be found on the website www.example.co.uk/services/current-vacancies.<br /> HTML: I want to convert them into clickable hyperlinks.
And, do you want them to be clickable as is? Or do you have another parser converting the links with http in front of them to actual clickable links?
Thanks for the reply. I'd like them to be clickable with just the www. There are thousands of records though so it will be impossible for me to know if they're all www or a mixture of www and http www