Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2011
    New Zealand
    Thanked 2 Times in 2 Posts

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

    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.

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

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 Posts
    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts