I'm trying to load a file and replace all variables in it with their values.
currently I'm doing it like this:
in my file (confirm.txt) I use varibles like this: "hi %name%, how are you?"
then I'm going to replace %name% with $name:
$message = fread($fp = fopen("confirm.txt", 'r'), filesize("confirm.txt"));
fclose($fp);
while(preg_match('/(%.+%)/U',$message, $matches) == TRUE){
$matchvar = str_replace('%','',$matches[1]);
$body_txt = str_replace($matches[1], $$matchvar, $message);
}
That's probably one of the worst way to do it!
Let me know if there's an easier way. I'd like to keep varibles in my file like this: "hi $name, how are you?"
thanx
Philippo