Einzelnen Beitrag anzeigen
Alt 29.07.2002, 10:15   #7
_m3
Inventar
 
Registriert seit: 24.09.2001
Beiträge: 7.335


Standard

Tom Christiansen hat da ein schönes Beispiel in Perl, dass Du sicher auch in PHP verwenden kannst:
Code:
 #!/usr/bin/perl 
 # urlify -- tchrist@perl.com
  require 5.002;  # well, or 5.000 if you see below
  
  $urls = '(' . join ('|', qw{
                http
                telnet
                gopher
                file
                wais
                ftp
            } ) 
        . ')';
  
  $ltrs = '\w';
  $gunk = '/#~:.?+=&%@!\-';
  $punc = '.:?\-';
  $any  = "${ltrs}${gunk}${punc}";
  
  while (<>) {
      ## use this if early-ish perl5 (pre 5.002)
      ##  s{\b(${urls}:[$any]+?)(?=[$punc]*[^$any]|\Z)}{&lt;A HREF="$1"&gt;$1&lt;/a&gt;}goi;
      ## otherwise use this -- it just has 5.002ish comments
      s{
        \b                          # start at word boundary
        (                           # begin $1  {
          $urls     :               # need resource and a colon
          [$any] +?                 # followed by on or more
                                    #  of any valid character, but
                                    #  be conservative and take only
                                    #  what you need to....
        )                           # end   $1  }
        (?=                         # look-ahead non-consumptive assertion
                [$punc]*            # either 0 or more puntuation
                [^$any]             #   followed by a non-url char
            |                       # or else
                $                   #   then end of the string
        )
      }{$1}igox;
      print;
  }
http://www.perl.com/doc/FMTEYEWTK/regexps.html
____________________________________
Weiterhin zu finden auf http://martin.leyrer.priv.at , http://twitter.com/leyrer , http://www.debattierclub.net/ , http://www.tratschen.at/ und via Instant Messaging auf Jabber: m3 <ät> cargal.org .
_m3 ist offline   Mit Zitat antworten