interpolating variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • magic_hat60622

    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($f h,filesize('./emails/confirmation/index.html'));
    }

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

    -Magic

  • slimdizzy

    #2
    Re: interpolating variables


    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($f h,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.

    Comment

    • Alvaro G. Vicario

      #3
      Re: interpolating variables

      *** 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($f h,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
      --

      Comment

      • dawnerd

        #4
        Re: interpolating variables


        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($f h,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?

        Comment

        • Jerry Stuckle

          #5
          Re: interpolating variables

          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_errorm sg) ;
          >>>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
          >>replacement s. 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.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Tim Hunt

            #6
            Re: interpolating variables


            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_errorms g) ;
            >>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_clea n or use str_replace like Alvaro said

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

            Comment

            Working...