I'm dumbstuck with regular expression (I cant see anything regular about it!)
I want to convert all URL's (eg "www.example.com") to html anchor href code and so far it worked until I came across www.example-domain.com where it failed at the hyphen ("-"). The code below outputs;
HTML Code:
<a href="http://www.example">www.example-domain.com</a>
PHP Code:
$HTML = eregi_replace('[^"/](www.[a-zA-Z0-9\.\/-/_\\&%=#]+)',' <a style="color:inherit;" href="http://\\1">\\1</a>',$HTML);
Just a couple of notes;
Note 1: I need to convert only www. references as http:// are not needed
Note 2: I can't convert all because images such as <img src="www.example.com/image.jpg"> would be converted to have <img src="<a href="www.example.com/image.jpg">www.example.com/image.jpg</a>"> in the middle.
The code above it not perfect and I can't yet implement BBCode for the job. I need a temp solution to the above problem but I cant make it get past the hyphen for some reason.
Please bare in mind that regular expression has always been my nemesis.
Please help
Kind regards
Dal
Bookmarks