note 74770 deleted from function.explode by tularis
| From: | tularis@php.net | Date: | Mon, 27 Oct 2008 13:06:28 +0000 |
| Subject: | note 74770 deleted from function.explode by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145823@lists.php.net to get a copy of this message | ||
Note Submitter: user at nospam dot com
----
<?php
// returns a string where $variables are replaced with their global value if available; removes all
extra whitespaces
function evaluateString($string) {
if ($string) { // check for value
$array = explode(' ', $string); // split into parts
foreach ($array as $word) { // each part
if ($word[0] == '$') { // is part a variable
if ($word = substr($word, 1)) { // get variable name
global ${$word}; // retrieve global value
$html .= ${$word}; // add value to string
} // end variable name check
} else { // not a variable
$html .= $word; // add word to string
} // end variable check
$html .= ' '; // add space between words
} // end part loop
} // end string check
return trim($html); // trims final space from end
} // end evaluateString
?>