note 33091 added to language.constants

From: Date: Mon, 16 Jun 2003 14:47:10 +0000
Subject: note 33091 added to language.constants
Groups: php.notes 
Request: Send a blank email to php-notes+get-50430@lists.php.net to get a copy of this message
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 ... ) ---- Manual Page -- http://www.php.net/manual/en/language.constants.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33091 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33091&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33091&report=yes

« previous php.notes (#50430) next »