Web Analytics Made Easy -
StatCounter clickable urls problem - CodingForum

Announcement

Collapse
No announcement yet.

clickable urls problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • clickable urls problem

    I´m using the following code to parse urls from the messages
    but when they do have a slash (like http://test.com/index.htm)
    the urls gets a /> (like http://test.com/index.htm />) at the
    end and the link continues untill the end of the message.

    Would someone be so kind in checking if something could be done at the code

    //begin PHP
    function make_clickable($buffer) {
    $buffer = eregi_replace("(^|[ \n\r\t])((http(s?)://)(www\.)?([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $buffer);
    $buffer = eregi_replace("(^|[ \n\r\t])((ftp://)(www\.)?([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $buffer);
    $buffer = eregi_replace("([a-z_-][a-z0-9\._-]*@[a-z0-9_-]+(\.[a-z0-9_-]+)+)","<a href=\"mailto:\\1\">\\1</a>", $buffer);
    $buffer = eregi_replace("(^|[ \n\r\t])(www\.([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $buffer);
    $buffer = eregi_replace("(^|[ \n\r\t])(ftp\.([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","\\1<a href=\"ftp://\\2\" target=\"_blank\">\\2</a>", $buffer);
    return $buffer;
    }

    ?>
    //end PHP

  • #2
    I use this:

    PHP Code:
    $finds[] = "/\[url=(.*?)\](.*)\[\/url\]/is";
            
    $replaces[] = '<a href="$1">$2</a>';
            
    $finds[] = '/(\A|\s)((http|ftp)+(s)?:-(\\/\\/)((\\w|\\.)+)(\\/)?(\\S+)?)(\Z|\s)/i';
            
    $replaces[] = ' <a href="$1">$6</a> ';
            
    $comment_text preg_replace($finds$replaces$comment_text); 

    Comment

    Working...
    X