SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2000
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey guys.
    I'm creating a hosted guestbook website, and its coming along well.
    I'm looking to implement a feature like hotmal does in emails, it converts urls to links. I'm guessing this would be a eregi function.
    So, for example, if the user guestbook message is $message, then i'd like to ereg('stuff in here',$message), so that it replace any links which are like:
    http://www.whatever.com
    with:
    <a href="http://www.whatever.com">
    Cheers,
    aJ

  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)
    Here is a nice way to do it, I got it from phpbuilder

    PHP Code:
    $urldstr eregi_replace("([url]http://[/url])(([[:alnum:]]|[[:punct:]])*)""<a href=\"\\0\">\\0</a>",$str); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2000
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers Freddy.
    [well, i'll check if it works ]

    Any chance of explaining it though, i mean, looks crazy. Why does it have <img src=images/smilies/tongue.gif> in?
    Hopefully that means it has a <code>:P</code> in it.
    ( thats a : then a P).
    -AJ

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah Sorry I have no idea how that got in there. It should be:

    PHP Code:
    $str "sflkghsdfkgjsdkjfg http://www.yahoo.com ds sflkg hfklsg fklds gfsdkl";
    $urldstr eregi_replace("(http://)(([[:alnum:]]|[[:punct:]])*)""<a href=\"\\0\">\\0</a>",$str); 
    Basically is says match anything with http:// and then anything until a space and replace it with and href tag around it.

    Seems like :p is a smilie in vb2 so that is why the tongue.gif is showing up take that image tag out and put in :p its place I will send you an email with the correct code int it.


    I seemed to have gotten to look as it should in vb2 now.
    Last edited by freddydoesphp; Mar 14, 2001 at 13:09.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2000
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy, thats great thanks.
    It ALMOST works!!
    The problem is, when replacing, it leaves the link open, and therefore ruins the other posts in the guestbook.

    i.e. if i enter:
    http://yahoo.com

    it replaces it with:
    <a href='

    but then stops there for some reason

    The code I am using is:
    Code:
    $message = eregi_replace("(http://)(([[:alnum:]]|[[:punct:]])*)", "<a href='\0'>\0</a>", $message);
    help greatly appreciated
    -aj

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah you need to turn off parsing urls in this forum and smilies to get to look right on the screen here but it should read.

    PHP Code:
    $message eregi_replace("(http://)(([[:alnum:]]|[[:punct:]])*)""<a href=\"\\0\">\\0</a>"$message); 
    Notice the two backslashes before the 0 in the replace argument you only had one backslash

    **AJ it keeps stripping the second backslash off before the 0 in the second arg. Just make sure where you see a 0 in the second arg to make sure there are two backslashes behind it in each case.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    AJ Can I email you the real code? So it doesn't get all screwed up with vb
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Zealot
    Join Date
    Jul 2000
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, course you can Freddy!

    I'd be very grateful.

    The reason why I removed the backslashes, though, is because usually, in my links, just to reduce the download of the page slightly, i try not to use quotes around things where I can.
    e.g. <img src=spacer.gif> I wouldn't bother with <img src="spacer.gif">, because in a big page, its just more code, really. Especially in a guestbook hosting system, where you need things to be fast.

    -aj

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't get used to it, as the world moves from html to other ways of producing data for the web, I believ strongly that a stricter method of coding is inevitable, I predict quotes will be mandatory in the future. Just my wacked out thoughts on the future of the web. I will send the code right over.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  10. #10
    SitePoint Zealot
    Join Date
    Jul 2000
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes! Thanks Freddy (Louie )

    Worked perfectly.
    Thanks alot for your help.
    -aj


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
  •