You could also have some fun with the preg_replace_callback function here.
Say the text is __NAME__ or __AGE__ and it refers to $yourArray['name'] and $yourArray['age']:
PHP Code:
<?php
$yourArray = array('name' => 'dave', 'age' = 32);
function getString($matches){
global $yourArray;
$match = $matches[1];
$lmatch = strtolower($match);
return array_key_exists($lmatch, $yourArray) ? $yourArray[$lmatch] : ('__' . $match . '__');
}
$yourString = "Hey, I'm __AGE__ and my name is __NAME__. Nice name, don't you think?";
$yourString = preg_replace_callback('/__([A-Z\d]+)__/', 'getString', $yourString);
echo $yourString;
You can then add as many array items and text keys as you want.
This can save you from having to manually search for your vars.
Bookmarks