Re: For the RegExps gurus!

From: Date: Thu, 06 Sep 2001 08:31:41 +0000
Subject: Re: For the RegExps gurus!
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-66163@lists.php.net to get a copy of this message
Sort of yes.... I thought it can be done with the /e modifier! Can't it be done with pure RegExps? "* R&Ze:" <renze@datalink.nl> wrote in message news:20010905121534.F19403@pro-pain.telemediair.nl... > <Original message> > From: _lallous <elias_bachaalany@yahoo.com> > Date: Wed, Sep 05, 2001 at 12:17:21PM +0200 > Message-ID: <20010905093745.77579.qmail@pb1.pair.com> > Subject: [PHP] For the RegExps gurus! > > > I want to write a RegExp that converts something like this: > > $mem = " > > Hello world! http://www.helloworld.com\n > > Hello world! ftp://ftp.server.com\n > > Hello world www.helloworld.com" > > > > how can I write a single regexp that converts $mem to this: > > $mem = " > > Hello world! <a > > > > href="http://www.helloworld.com">http://www.helloworld.com</a>\n > > Hello world! <a > > href="ftp://ftp.server.com">ftp://ftp.server.com</a>\n > > Hello world <a > > > > href="http://www.helloworld.com">http://www.helloworld.com</a>" > > > > As you noticed that the second line didn't have the protocol specifier and > > it took by default "http://" and the ones that > > had a protocol specifier were > > kept as is. > > </Original message> > > <Reply> > > This should do the job: > > --- PHP code --- > <PRE> > <?php > > $mem = "Hello world! http://www.helloworld.com\n > Hello world! ftp://ftp.server.com\n > Hello world www.helloworld.com"; > > /* ------ ! Here's your regexp ! ------ */ > $mem = preg_replace > ("/\s+([http:|ftp:]{0,1}\S+\.\S+)/me", "' <A > href=\"'. > (ereg('^[http:|ftp:]','\\1') > ? '\\1\">\\1</A>' > : > 'http://\\1\">http://\\1</A>')", $mem); > > print ($mem); > > ?> > </PRE> > --- End of PHP code --- > > Let me know if this was what you were looking for... > > </Reply> > > -- > > * R&zE: > > > -- »»»»»»»»»»»»»»»»»»»»»»»» > -- Renze Munnik > -- DataLink BV > -- > -- E: renze@datalink.nl > -- W: +31 23 5326162 > -- F: +31 23 5322144 > -- M: +31 6 21811143 > -- > -- Stationsplein 82 > -- 2011 LM HAARLEM > -- Netherlands > -- > -- http://www.datalink.nl > -- ««««««««««««««««««««««««

« previous php.general (#66163) next »