Re: [PHP4BETA] Regex question

From: Date: Tue, 28 Mar 2000 14:12:02 +0000
Subject: Re: [PHP4BETA] Regex question
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-12734@lists.php.net to get a copy of this message
On Mon, 27 Mar 2000, Dan Murphy wrote: > setting up a simple template library I am running into the following problem > > $newline = pgreg_replace("%%(\w+)%%", "$HTTP_POST_VARS[\\1]", $line); > > generates the following error. > > Parse error: parse error, expecting T_STRING' or > T_VARIABLE' or `T_NUM_STRING' in > /export/home/virtual01/bsc/test.php on line 10 > > getting rid of the $HTTP_POST_VARS and just replacing with \\1 works correctly and > vice versa if I remove the \\1 and replace with something like $HTTP_POST_VARS[username] > it works fine. > > the goal is to prefill in form values... pretty straight forward. > > > the same thing works in perl ..well the equivalent expression anyway > > $line =~ s/%%(\w+)%%/$MY_DATA{$1}/g; > > Just wondered if anyone new a quick work around. Use this: $newline = preg_replace("/%%(\w+)%%/e", "\$HTTP_POST_VARS[\\1]", $line); -Andrei The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall

« previous php.version4 (#12734) next »