note 112747 deleted from language.variables.variable by cmb

From: Date: Sun, 12 Jan 2020 08:32:14 +0000
Subject: note 112747 deleted from language.variables.variable by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213863@lists.php.net to get a copy of this message
Note Submitter: David Forger ---- Parse an imported string e.g. from a database for php variable names and replace them with their values. example: In the String "Dear $firstname $lastname, welcome to our Homepage" the variables shall be replaced with the respective values. <?php $welcome = getImportedString(); $firstname = "David"; $lastname = "Forger"; echo $welcome; // before replacement output will be: //"Dear $firstname $lastname, welcome to our Homepage" function replaceVars($match) { return $GLOBALS[$match[1]]; } $welcome = preg_replace_callback('/\$(\w+)/i', "replaceVars", $welcome); echo $welcome; //now output will be: //"Dear David Forger, welcome to our Homepage" ?>

« previous php.notes (#213863) next »