Reading HTML file containing PHP variable into a string
Posted: Wed Jan 07, 2004 9:03 am
This is a scenario....
I have a HTML file, which contains PHP variables, or rather say I have HTML file which I want to include and insert PHP variable in it.
Okay, let me get it straight......
I need to send a Mail (HTML mail), for that I have made a HTML file which is format in which mail need to be send, previously I use to copy the whole HTML code in a string. But when I need to make changes in format It use to be a big PITA, so instead now what I want to do is use an external HTML file.
The thing is some of the part of this HTML file is need to be dynamic, PHP variable which are posed by form.
Somehow using following function I could get content of HTML file in string, but PHP vaible copies as normal HTML text.
check this out...
My HTML file is like this
as you can see there are PHP variables in HTML code, When I use this code from external HTML file, they output as they are that is.. in final output $from remains as simple text $from, while it's suppose to be Name entered in Form, If I use this code in my Mail Program, it works as charm.
so, after all this long blah blah, here comes the million dollar question..
How I can read a HTML file containing PHP variable into a sinle string ?

**EDIT**
okay I tried even removing all line breaks in HTML file, thus making it a single line code, but STILL THE DAMN THING DOESN'T WORK...
I have a HTML file, which contains PHP variables, or rather say I have HTML file which I want to include and insert PHP variable in it.
Okay, let me get it straight......
I need to send a Mail (HTML mail), for that I have made a HTML file which is format in which mail need to be send, previously I use to copy the whole HTML code in a string. But when I need to make changes in format It use to be a big PITA, so instead now what I want to do is use an external HTML file.
The thing is some of the part of this HTML file is need to be dynamic, PHP variable which are posed by form.
Somehow using following function I could get content of HTML file in string, but PHP vaible copies as normal HTML text.
check this out...
Code: Select all
<?php // File_Get_Content Function
function file_get_contents($f) {
ob_start();
$retval = @readfile($f);
if (false !== $retval) { // no readfile error
$retval = ob_get_contents();
}
ob_end_clean();
return $retval;
}
?>Code: Select all
<html>
<body>
<table width="500" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td height="30" colspan="3" class="headText">Sender's Information</td>
</tr>
<tr>
<td width="100" height="20" class="genText"><strong>Name</strong></td>
<td width="30" class="genText"><strong>:</strong></td>
<td width="370" class="genText">$sender</td>
</tr>
<tr>
<td height="20" class="genText"><strong>Email</strong></td>
<td class="genText"><strong>:</strong></td>
<td class="genText">$from</td>
</tr>
<tr>
<td height="20" class="genText"><strong>Phone</strong></td>
<td class="genText"><strong>:</strong></td>
<td class="genText">$phone</td>
</tr>
</table>
</body>
</html>so, after all this long blah blah, here comes the million dollar question..
How I can read a HTML file containing PHP variable into a sinle string ?
**EDIT**
okay I tried even removing all line breaks in HTML file, thus making it a single line code, but STILL THE DAMN THING DOESN'T WORK...