Re: parsing a string

From: Date: Wed, 31 Oct 2001 22:22:21 +0000
Subject: Re: parsing a string
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-73085@lists.php.net to get a copy of this message
"Yz James" <liljim@btconnect.com> wrote in message news:20011018180037.5536.qmail@pb1.pair.com... > Hey John, > something like this might work: > > <? > > $string = "This is a string with an embedded image [bird.gif,this is a > bird]"; > > $string = preg_replace("/\[(.*?\.)(gif|jpg),(.*?)\]/i", "<img src=\"\\1\\2\" > alt=\"\\3\">", $string); > > echo $string; > > ?> Great!. I love it when I see stuff like this written by someone who knows regex better than I. The ability to insert the pieces that are recognized/extracted via \1, \2 is pretty cool. Thanks. -- John A. Grant * I speak only for myself * (remove 'z' to reply) Radiation Geophysics, Geological Survey of Canada, Ottawa If you followup, please do NOT e-mail me a copy: I will read it here

« previous php.general (#73085) next »