Re: Converting URL's to hyperlinks.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/9/4 Daevid Vincent <daevid@xxxxxxxxxx>

>
>
> > -----Original Message-----
> > From: Lupus Michaelis [mailto:mickael+php@xxxxxxxxxxxx<mickael%2Bphp@xxxxxxxxxxxx>
> ]
> > Sent: Friday, September 04, 2009 7:46 AM
> > To: php-general@xxxxxxxxxxxxx
> > Subject: Re:  Converting URL's to hyperlinks.
> >
> > Daevid Vincent a écrit :
> > > Maybe I misunderstood the OP,
> >    OP ?
>
> Original Poster
>
> > > but wouldn't this (or something like it) be
>
> Note the "something like it". I didn't write his app, just provided a
> starting point.
>
> > > $url = preg_replace("/(\w+@\w+\.[a-zA-Z]{2,3})/i", "<a
> > > href='mailto:$1'>$1</a>", $url);
> >    This violate the numerous RFC about mail addresses, and some other
> > stuffs.
>
> Blah blah blah.
> I've used this code for about 6 years now and have yet to find emails that
> it didn't work for. If someone has some funky (whacky) RFC extremity, then
> so be it. That's their problem. Most people have NORMAL emails that follow
> the above.
>
> But you are correct, I have revised it to be a little more forgiving of
> some
> allowed characters...
>
> preg_replace("/([\w\.\-_]+@[\w\.\-_]+\.\w{2,6})/i",
>
> > >
> > > $url =
> > preg_replace("/\s(http:\/\/)?(\w*\.?\w*\.[a-zA-Z]{2,3}.*?\s)/i", " <a
> > > href='http://$2' target='_blank'>$2</a>", $url);
> >
> >    Same as previously. What about .info, .museum and so on tld ?
>
> What about them? It's going to depend on how/where you use this. In my
> case,
> 2 and 3 letter domains are all I encounter. It's trivial to make it {2,6}
> if
> you really are going to encounter a .museum domain. DOUBTFUL, but sure,
> I'll
> concede the three extra letters. ;-)
>
> However, you point out a few edge cases and so I optimized mine and now use
> this one:
> http://snipplr.com/view/2371/regex-regular-expression-to-match-a-url/
>
> > > Oh, and your regex isn't
> > smart (you use the case insensitivity flag, but seek A-Z
> > characters...) :D
>
> Noted. Thanks for the optimization.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Thanks for posting that! Will be really handy for me!

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux