Re: preg_replace

From: Date: Mon, 13 Mar 2000 15:20:18 +0000
Subject: Re: preg_replace
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-16750@lists.php.net to get a copy of this message
On Sun, 12 Mar 2000, Andrew Coldham wrote: > class test{ > var var1; > function printit(){ > echo preg_replace("/DATA_([A-Z]+)/e", > "$this->showX('\\1',\"$this->var1\")", $inputstring); // > doesn't work > echo preg_replace("/DATA_([A-Z]+)/e", "showX('\\1')", > $inputstring); // > works great > } > function showX($param){ > if ("NAME" == $param) > return $this->var1; > } > } > > This doesn't work, ideas? It breaks if i pass in $this->anyfunction() works > great with a function that's not defined in the current class. > Also doesn't work if var1 is a complex type. You need to use "\$this->showX..." for the replacement string. Basically, escape the $. -Andrei It is commonly the case with technologies that you can get the best insight about how they work by watching them fail. -- Neal Stephenson

« previous php.dev (#16750) next »