Re: replacing dynamic variable in preg_replace

From: Date: Thu, 16 Sep 2004 03:13:01 +0000
Subject: Re: replacing dynamic variable in preg_replace
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-36215@lists.php.net to get a copy of this message
Steve Morgan wrote:
I am working on a script which takes a list of variables form a database. The problem i am currently having is some of the variables have other variables in the content , i.e. $temp="<h1>$title</h1>" (made up example), is something that might come out of the mysql. $query=mysql_query("SELECT code,varname FROM k_sys");
     while(list($code,$var)=mysql_fetch_array($query)){
       $code=str_replace("-user-",USER,$code);
       $code=preg_replace("/--(\w+)--/","$$1",$code); // PROBLEM
       $$var=$code;
} is the current code, i'm setting off variables with a --, so if variables $title, is in the mysql, the above example would be <h1>--title--</h1> instead. When i do the above i would just get like $title as an output. I think its due to how mysql is storing the information, but a stripslashes didnt work. If anyone can help it'd be much appreciated.
preg_replace('/--(\w+)--/e','$$1',$code); -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.db (#36215) next »