note 33091 deleted from language.constants by philip

From: Date: Sat, 05 Jul 2003 18:13:16 +0000
Subject: note 33091 deleted from language.constants by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-51566@lists.php.net to get a copy of this message
Note Submitter: jochem@drecomm.nl ---- fmmarzoa at gmx dot net wrote: ---------------------------------------------- ... I've had a trouble with constants that must include variable values, in example, I've something like: define (strArticleDescr, 'Published by $article_author on $article_date in $article_lang_name'); Now, when I try to use this, the value is interpreted literally, so: print strArticleDescr; Will show: Published by $article_author on $article_date in $article_lang_name I've found a solution for this using 'eval' for parsing the constant, thats: eval ('print "'.strArticleDescr.'";') And now things works ok, like in example: Published by Francisco M. Marzoa on 2002-10-09 15:39:10 in Spanish ---------------------------------------------- You can also use a simple str_replace: The define looks like this then: define (strArticleDescr, 'Published by ##article_author## on ##article_date## in ##article_lang_name##'); Now when you print the next you will also get the desired result (without a riscfull eval): print str_replace('##article_author##', $article_author, str_replace('##article_date##', $article_date, str_replace('##article_lang_name##', $article_lang_name, strArticleDescr))); Instead of ##varname## you can use lots of other ways ( {VARNAME} is used in PHPBB ... )

« previous php.notes (#51566) next »