I'm building this site with a fairly crude little CMS, and I'm trying to figure out how, when the site owner includes a URL as part of, lets say a news article, I can recognise that it's a URL, then add anchor tags at either end. I found feyd's great intro to regex, which showed me how to recognise a URL, but after that, I'm way out of my depth here.
So far:
Code: Select all
if (preg_match("#^\w+://(www\.)?\w+\.\w+#i", $content)) {
Also, will the above find URLs within the $content string, or is it looking for the whole string to be a URL?
Many, many thanks in advance. The page in question is here:
http://www.marianneanderson.co.uk/new/news.php
You can see from the owner's news entry why I'd like to figure this out.