Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post

    makeing links clickable with PHP

    Hey there, I want my php code to recognise links and make them clickable automaticly. I found this scrpt that works fine:

    PHP Code:
    <?php

    function makeClickableLinks($text) {

      
    $text eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
        
    '<a href="\\1">\\1</a>'$text);
      
    $text eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
        
    '\\1<a href="http://\\2">\\2</a>'$text);
      
    $text eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
        
    '<a href="mailto:\\1">\\1</a>'$text);
      
    return 
    $text;

    }

    // Usage

    // Email address example
    $text "you@example.com";
    echo 
    makeClickableLinks($text);

    echo 
    "<br /><br />";

    // URL example
    $text "http://www.example.com";
    echo 
    makeClickableLinks($text);

    echo 
    "<br /><br />";

    // FTP URL example
    $text "ftp://ftp.example.com";
    echo 
    makeClickableLinks($text);

    ?>
    But is there a way of making it recognise google.com and www.google.com

    thanks for your time.

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    I've been trying to do this same thing,
    and it seems to me that with would building some kind of array for all of the possible domain extensions that this is not possible.

    example ".com,.net,.ca".. and so on.
    if you had this, I don't see any reason why it shouldn't work.

    I've actually been trying to find a way to make it skip links that are already "clickable" ( coming out of a large already existing data base ), but haven't had a chance to finish yet.

    good luck!
    -Ken

  • #3
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    TY ken,

    Just found some more code in the phpbb script, as its free ware it should be ok for me to use.

    this lets me do www.google.com

    but still stuck on google.com


  •  

    Posting Permissions

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