I am having trouble reading in a file and using it as a template in PHP. A portion of my code is pasted below. For some reason it never finds $$USER_NAME$$ in the string so it never replaces. I also pasted the beginning part of my template below.
$filename = "email/templates/welcome.txt";
$file = fopen($filename, "r")
$body = fread($file, filesize($filename));
fclose($file);
$body = str_replace("$$USER_NAME$$", "John Doe", $body);
print($body);
Template:
<p>
<img src="emailPic" alt="Logo" />
</p>
<p>Dear $$USER_NAME$$,</p>
<p>Thank you for registering to attend $$EVENT_NAME$$. We look forward to helping you reach your networking goals at $$EVENT_SHORT_NAME$$.
</p>...
Any ideas about why it wouldn’t find $$USER_NAME$$ in the template?
Try with single quotes:
otherwise the
$signs get interpreted by PHP (just try to doecho "$$USER_NAME$$"to understand that PHP will interpret it asecho $$USER_NAME."$$"or something similar).You can as well resolve the problem by escaping the
$if you still want to use double quotes:Check the PHP manual page on Strings to know what are the differences between single quoted and double quoted strings in PHP.