473,513 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

interpolating variables

hi all. I have an html file that I need php to read and send as an html
e-mail. The file contains standard html and also some variable names
that I want php to interpolate:
<html>
Hi there. my name is $name
</html>

I'm reading the file like so:
$fh=fopen('./emails/confirmation/index.html', 'r') or die
($php_errormsg) ;
while (! feof($fh)){
$body.=fread($fh,filesize('./emails/confirmation/index.html'));
}

PHP is not interpolating the variable names in the email. Solutions?

-Magic

Aug 4 '06 #1
5 1291

magic_hat60622 wrote:
hi all. I have an html file that I need php to read and send as an html
e-mail. The file contains standard html and also some variable names
that I want php to interpolate:
<html>
Hi there. my name is $name
</html>

I'm reading the file like so:
$fh=fopen('./emails/confirmation/index.html', 'r') or die
($php_errormsg) ;
while (! feof($fh)){
$body.=fread($fh,filesize('./emails/confirmation/index.html'));
}

PHP is not interpolating the variable names in the email. Solutions?

-Magic
Why not just put the html of the message you want to send into a
variable in that script??
Are there reason why your reading a file for such a small amout of
text/html??

Just seems to be more work then needed unless you have users making
these files and want them to be in a static place for your script to
read from.

Aug 4 '06 #2
*** magic_hat60622 escribió/wrote (4 Aug 2006 09:31:59 -0700):
$fh=fopen('./emails/confirmation/index.html', 'r') or die
($php_errormsg) ;
while (! feof($fh)){
$body.=fread($fh,filesize('./emails/confirmation/index.html'));
}

PHP is not interpolating the variable names in the email. Solutions?
Thanks God, PHP does not treat all files it reads as PHP code! Just use
str_replace() on $body to replace the values you want. I suggest, though,
that you chose another markup that's not so prone to undesired
replacements. Some ideas:

{$foo}
%FOO%
[%foo%]

....

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Aug 4 '06 #3

Alvaro G. Vicario wrote:
*** magic_hat60622 escribió/wrote (4 Aug 2006 09:31:59 -0700):
$fh=fopen('./emails/confirmation/index.html', 'r') or die
($php_errormsg) ;
while (! feof($fh)){
$body.=fread($fh,filesize('./emails/confirmation/index.html'));
}

PHP is not interpolating the variable names in the email. Solutions?

Thanks God, PHP does not treat all files it reads as PHP code! Just use
str_replace() on $body to replace the values you want. I suggest, though,
that you chose another markup that's not so prone to undesired
replacements. Some ideas:

{$foo}
%FOO%
[%foo%]

...

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Why not just use .php instead of .html?

Aug 4 '06 #4
dawnerd wrote:
Alvaro G. Vicario wrote:
>>*** magic_hat60622 escribió/wrote (4 Aug 2006 09:31:59 -0700):
>>>$fh=fopen('./emails/confirmation/index.html', 'r') or die
($php_errormsg) ;
while (! feof($fh)){
$body.=fread($fh,filesize('./emails/confirmation/index.html'));
}

PHP is not interpolating the variable names in the email. Solutions?

Thanks God, PHP does not treat all files it reads as PHP code! Just use
str_replace() on $body to replace the values you want. I suggest, though,
that you chose another markup that's not so prone to undesired
replacements. Some ideas:

{$foo}
%FOO%
[%foo%]

...

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--


Why not just use .php instead of .html?
Because PHP will still not parse a file read with fread(), no matter
what the extension.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 5 '06 #5

Jerry Stuckle wrote:
dawnerd wrote:
Alvaro G. Vicario wrote:
>*** magic_hat60622 escribió/wrote (4 Aug 2006 09:31:59 -0700):

$fh=fopen('./emails/confirmation/index.html', 'r') or die
($php_errormsg) ;
while (! feof($fh)){
$body.=fread($fh,filesize('./emails/confirmation/index.html'));
}

PHP is not interpolating the variable names in the email. Solutions?

Thanks God, PHP does not treat all files it reads as PHP code! Just use
str_replace() on $body to replace the values you want. I suggest, though,
that you chose another markup that's not so prone to undesired
replacements. Some ideas:

{$foo}
%FOO%
[%foo%]

...

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--

Why not just use .php instead of .html?

Because PHP will still not parse a file read with fread(), no matter
what the extension.
Could turn on output buffering, include a php file + call
output_get_clean or use str_replace like Alvaro said

Thats if a template is necessary though, slimdizzy had a point

Aug 5 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3307
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
5
11801
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
1
2802
by: jitasi | last post by:
Hi all I want to use the matlab function "pchip" in python. I have checked the scipy, but there is only spline Interpolating. Are there any pchip Interpolating in python? Thanks Steven
1
29312
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.