Re: [PHP4BETA] preg_replace Q

From: Date: Thu, 20 Apr 2000 18:03:12 +0000
Subject: Re: [PHP4BETA] preg_replace Q
References: 1 2 3 4  Groups: php.version4 
Request: Send a blank email to php-version4+get-13824@lists.php.net to get a copy of this message
On Thu, 20 Apr 2000, Cynic wrote: > BTW, problem wasn't that it didn't evaluate, but that it > didn't, and still doesn't replace. > > At 09:02 20.4.2000 -0500, Andrei Zmievski wrote the following: > -------------------------------------------------------------- > >On Thu, 20 Apr 2000, Cynic wrote: > > > $output = preg_replace( "/\$(\w+)/" , > > > "/\$GLOBALS['\\1']/" , $output ) ; > > > > > > I need to replace $var with $GLOBALS['var'], however the regexp above > > > doesn't work. What am I doing wrong? > > > >$output = preg_replace( "/\$(\w+)/e" , "\$GLOBALS['\\1']" , > >$output ) ; Ok, the problem is that regular expression engine sees your $ and thinks you're searching for the end of the string. What you should do is this: $output = preg_replace( "/\\\$(\w+)/e" , "\$GLOBALS['\\1']" , $output ) ; -Andrei Any sufficiently advanced Operating System is indistinguishable from Linux. - Jim Dennis

« previous php.version4 (#13824) next »