View Full Version : text to link conversions (don't convet a certain range of urls).

04-14-2012, 08:23 AM
Hello all, I'm working on a custom made forum for a project. It's going pretty well but I've come across a problem and I need to find a solution to it.

Well, to enlighten you on what I'm doing I've got a little image uploader attached to my comment box, the image uploader uses the imageshack tool. I've also got a function which turns text into links (when appropriate of course).

When the webpage displays a imageshack.us link it'll fail to display the image as my link converter below blocks a bit of the image link. I'd like to make it so if the text contains the address imageshack.us it doesn't try to convert the link and it'll display the image as per normal.

$comment = nl2br($info['tContent']);
$comment = preg_replace("/((ftp)|(http(s?))\:\/\/(([A-z0-9\-\:\;\.\@\/]+)))/is",'<a href="\\0">\\0</a>',$comment);
echo "$comment";

Thank you, hopefully I've explained my problem well enough and somebody will have a suggestion on how I can prevent these links from getting converted.

Have a good one.

04-14-2012, 07:42 PM
I don't quite follow exactly what you are looking to do. But the pattern for a uri isn't correct, as it can contain a querystring to it, and that will cause problems when requesting dynamic content. You are missing the sections that allow the ? and key=value pairs within it.
Cheap solution? Add ? and = as a part of the pattern it will allow, maybe add in # as well since it could have a hashtag on it too. The reaaalllllyyy cheap solution would be to just match anything that is not \s, and then terminate on \s, .(actual period), end of line, or $.
Heavy solution requires splitting up of the DNS from the querystring, and scanning each part of it to verify a match. Its surprisingly complicated as to what is allowed, and has a pile of little rules. That only verifies that the uri structure is valid, not that it would actually go anywhere.