variables in text or placeholders

From: Date: Wed, 27 Jun 2001 15:21:27 +0000
Subject: variables in text or placeholders
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-55410@lists.php.net to get a copy of this message
another way of doing it would be to ditch using variables in the actual text string altogether, and just use place holders.... use {varname} instead of $varname, and then you dont need to eval anything... just use a simple regexp $fullname = "Roy Rogers"; $data = array( 'name' => 'Johnny', 'webname' => 'jn4523', 'this' => $this, 'fullname' => $fullname, ); $text = "Dear {name}, your webhosting acccount {webname} is ready for {fullname}..."; print preg_replace('/{(.*?)}/e', '$data[$1]', $text); > -----Original Message----- > From: Kristian Duske [mailto:ml.duske@gmx.net] > Sent: Tuesday, June 26, 2001 7:28 AM > To: php-general > Subject: RE: [PHP] sending e-mail with variables > > > > $subject =$row["msub"]; //"Your webhosting account at > > $hostname.$domain$tld"; > > $message .= $row["mline1"]; //"Dear $fullname,\n"; > > > > $message .= $row["mline2"];//"Your webhosting account has been > > created. Please use the\n"; > > $message .= $row["mline3"];//"following data to log in:\n"; > > Now my problem is it does not fill in the variables when it sends the > > e-mail.The reason I am doing this is the end user of this program > > what's to be able two > > change what the e-mail says. How can I do this so it fills the > > variables in. Or am I going about this totally wrong > > If I understand you correctly, you have to eval the code that you get from > the database. That would be: > > $subject = eval($row["msub"]); > > This interpretes the string that is stored in $row["msub"] as php code and > assings the result of the interpretation to $subject. Make sure that you > have assigned all variables that you use in $row["msub"] before you eval it. > > Kristian > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#55410) next »