RE: [PHP] Odd Strpos Behavior

From: Date: Thu, 12 Dec 2002 01:09:21 +0000
Subject: RE: [PHP] Odd Strpos Behavior
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-127940@lists.php.net to get a copy of this message
> >It'd be easier to use a regular expression for something like this. > >Something like this would work (from PHP Architect): > > > >$s = "I am going to be {a} years old on the {b}th of November, {c}."; > >$a = array( > >"a" => "one hundred", > >"b" => "seventeen", > >"c" => "two thousand two"); > >$z = preg_replace("/\{([a-z]+)\}/e","\$a['$1']",$s); > >echo $z; > >Output: > >I am going to be one hundred years old on the seventeenth of November, > >two thousand two. > > Now that I've been shown what you meant, and had a chance to play with it, > I can see that it's not really going to work out for me. The reason is, I > don't know in advance what the contents of the [] will be. Okay, so how do you know what to replace something like [author] with? What exactly are you doing again? I've forgotten the original question. :) I'm sure there is a better, faster way to do it with regular expressions or something similar that going digit by digit and looking for [ and ], etc... ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#127940) next »