SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've made a guestbook and in the "free text area" people might write some links.
    How do i change "http://www.blah.com" or "http://www.blah.com" to <a href=http://www.blah.com></a>?

    i know i should use eregi() in PHP but i just can't figure out the rest

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well the first thing you will want to check for is the existence of http:// if it is there we should remove after we create the link to make it look prettier like so:
    $url = "http://www.yahoo.com";
    //Chekc for existence of http://
    if (eregi("http://", $url)) {
    //If http:// present remove for the display
    $link = sprintf('<a href="%s">%s</a>', $url, eregi_replace("http://", "", $url));
    }
    else {
    $link = sprintf('<a href="http://%s">%s</a>', $url, $url);
    }
    print $link;
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Freddy
    can I include it in the beginning of the script (before the connect to MySql)?


Bookmarks

Posting Permissions

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