Re: ereg_replace with assoc array?

From: Date: Fri, 09 Feb 2001 01:44:45 +0000
Subject: Re: ereg_replace with assoc array?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-38867@lists.php.net to get a copy of this message
Thanks for the feedback! From the docs it appears that I can do this: $string = file.tpl; //html mixed with {placeholders} $array = fetch_mysql_array($result, MYSQL_ASSOC); //array of field => values echo strtr($string, $array); //passing only 2 arguments means 2nd is array one thing - I want to use special {} characters in my file.tpl. Does anyone know if there is some way I can tell strtr to only evaluate items in {} tag for replacing? regards, jaxon On 2/8/01 5:49 PM, "Brad S. Jackson" <bjackson@McLeodUSA.com> wrote: > > > See the documentation for strtr and preg_replace. > > http://www.php.net/manual/en/html/function.strtr.html > http://www.php.net/manual/en/html/function.preg-replace.html > > > "Jaxon" <jaxon@salamander.net> wrote: > Hi > > Can I do this???? > > $string = file.tpl; > > while (list($pattern, $replacement) = each($array)) { > ereg_replace ($pattern, $replacement, $string); > } > > echo $string; > > > > note some assumptions below: > > $array contains an assoc array: > > first foo > second bar > third rab > fourth oof > > file.tpl is this: > > some html {first} > more html {second} > even more html {third} > lots more html {fourth} > > This seems like a slow way to do this... > any advice is welcome! > > tia! > jaxon > > >

« previous php.general (#38867) next »