SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Winemaster bronze trophy BonRouge's Avatar
    Join Date
    Oct 2004
    Location
    Sendai, Japan
    Posts
    2,417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    replace 'http://sitepoint.com' with 'sitepoint'

    Hey.
    I've tried asking this before but had no real help...
    I'm using preg_replace to... well, to replace stuff. How could I use it to replace 'http://sitepoint.com' with 'sitepoint' (with a link). It's for site comments / messages - like a forum, but a little different (at the bottom of this page is an example).
    So, a user types in http://...etc and on screen we see a link to the site with the url parsed down to the site name.

    I'd appreciate any help.

    Thanks a lot.

  2. #2
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try sometihng like this, I haven't tested it by the way, so I'm not sure if it'll work:

    PHP Code:
    $link preg_replace('/(http:\/\/){1}([a-z0-9\-]+\.)+([a-z0-9\-]+){1}(\.[a-z]{2,6}){1}/i''<a href="\\1\\2\\3\\4">\\3</a>'$input); 

  3. #3
    Winemaster bronze trophy BonRouge's Avatar
    Join Date
    Oct 2004
    Location
    Sendai, Japan
    Posts
    2,417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great! Thanks a lot -that did it.
    I don't understand it, but I'll try to.

    Thanks again.


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
  •