Including html files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary L. Burnore

    #16
    Re: Including html files

    On 23 Jun 2004 04:58:07 -0700, davidaak@yahoo. com (David Johnson)
    wrote:
    [color=blue][color=green]
    >> First of all, why would you ever want to include() an HTML file?[/color]
    >
    >Sounds like I wouldn't since it doesn't support what I want to do.
    >[color=green]
    >> readfile() is faster...[/color]
    >That's fine but it doesn't support $variables.[/color]

    Yeah, but you can str_replace to your hearts content.

    [color=blue]
    >[color=green]
    >>
    >> Second, HTML files are not supposed to be "containing $variables";
    >> only PHP files are.[/color]
    >
    >Not supposed to? There's nothing in the HTML spec that prohibits
    >text from containing dollar signs.[/color]

    Maybe he should have said "Really shouldn't" ?

    [color=blue]
    >[color=green]
    >>
    >> Third, what you seem to want is probably achievable with eval(),
    >> although I am still at a loss what it is you are trying to accomplish
    >> in such a convoluted way...[/color]
    >
    >Only convoluted if php doesn't support it in a simple function call.
    >Which appears to be the case. Funny how it takes longer for people to say
    >"I don't know" than almost anything else.
    >
    >For your information, I am trying to do bare-bones templates.[/color]

    For his information? He was trying to be nice in suggesting you post
    what you're trying to DO so people could help you.

    [color=blue]
    >I know
    >there are several fine template packages, but I don't want all the
    >function or overhead they provide. I want to put all of my html in
    >one file with variable names instead of text. The html would never be
    >displayed as such so no one but me would see the variable names.
    >But I want to use an html editor to edit these files and be able to
    >display them in a web browser. My php program would then "include" the
    >html file, substituting text for the variables.[/color]

    use readinfile to store your file in $htmldoc;

    $htmldoc = str_replace(Var iable1, $value1, $htmldoc)
    $htmldoc = str_replace(Var iable2, $value2, $htmldoc)
    $htmldoc = str_replace(Var iable3, $value3, $htmldoc)
    $htmldoc = str_replace(Var iable4, $value4, $htmldoc)


    echo $htmldoc;

    How hard is that?

    [color=blue]
    >
    >php comes very close to supporting this. An included file can contain
    >php and a here-doc but that spoils it for display by a web browser.
    >If you could imbed an external text file while you're in a here-doc,
    >you could get what I'm looking for. But, of course, everything in a
    >here-doc is interpreted as straight text, not commands.
    >[/color]

    Then maybe you should join the PHP team and WRITE it?


    --
    gburnore@databa six dot com
    ---------------------------------------------------------------------------
    How you look depends on where you go.
    ---------------------------------------------------------------------------
    Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
    | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
    DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
    | ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
    Black Helicopter Repair Svcs Division | Official Proof of Purchase
    =============== =============== =============== =============== ===============
    Want one? GET one! http://www.databasix.com
    =============== =============== =============== =============== ===============

    Comment

    • David Johnson

      #17
      Re: Including html files

      > First of all, why would you ever want to include() an HTML file?

      Sounds like I wouldn't since it doesn't support what I want to do.
      [color=blue]
      > readfile() is faster...[/color]
      That's fine but it doesn't support $variables.
      [color=blue]
      >
      > Second, HTML files are not supposed to be "containing $variables";
      > only PHP files are.[/color]

      Not supposed to? There's nothing in the HTML spec that prohibits
      text from containing dollar signs.
      [color=blue]
      >
      > Third, what you seem to want is probably achievable with eval(),
      > although I am still at a loss what it is you are trying to accomplish
      > in such a convoluted way...[/color]

      Only convoluted if php doesn't support it in a simple function call.
      Which appears to be the case. Funny how it takes longer for people to say
      "I don't know" than almost anything else.

      For your information, I am trying to do bare-bones templates. I know
      there are several fine template packages, but I don't want all the
      function or overhead they provide. I want to put all of my html in
      one file with variable names instead of text. The html would never be
      displayed as such so no one but me would see the variable names.
      But I want to use an html editor to edit these files and be able to
      display them in a web browser. My php program would then "include" the
      html file, substituting text for the variables.

      php comes very close to supporting this. An included file can contain
      php and a here-doc but that spoils it for display by a web browser.
      If you could imbed an external text file while you're in a here-doc,
      you could get what I'm looking for. But, of course, everything in a
      here-doc is interpreted as straight text, not commands.

      Maybe there is another way to do it, such as with an eval. But, as
      you say, it tends to get convoluted.
      [color=blue]
      >
      > Cheers,
      > NC[/color]

      And to you. And thanks to everyone who offered suggestions.

      Comment

      • Nikolai Chuvakhin

        #18
        Re: Including html files

        davidaak@yahoo. com (David Johnson) wrote in message
        news:<b1ee3f2a. 0406230358.357b c78d@posting.go ogle.com>...[color=blue]
        >[color=green]
        > > Second, HTML files are not supposed to be "containing $variables";
        > > only PHP files are.[/color]
        >
        > Not supposed to? There's nothing in the HTML spec that prohibits
        > text from containing dollar signs.[/color]

        That's right, but in PHP's default setup *.htm[l] files are not
        parsed by the PHP interpreter.
        [color=blue]
        > For your information, I am trying to do bare-bones templates. I know
        > there are several fine template packages, but I don't want all the
        > function or overhead they provide. I want to put all of my html in
        > one file with variable names instead of text. The html would never be
        > displayed as such so no one but me would see the variable names.
        > But I want to use an html editor to edit these files and be able to
        > display them in a web browser. My php program would then "include" the
        > html file, substituting text for the variables.[/color]

        OK, now we're talking. Here's how you can do this.

        Let's say you have a file 'intro.htm':

        <html>
        <h1>Hello, my name is $name</h1>
        </html>

        Then, you have this script:

        $name = 'David Johnson';
        $content = '$newcontent = "' .
        str_replace('"' , '&quot;', file_get_conten ts('intro.htm') ) .
        '";';
        eval($content);
        echo $newcontent;

        Voila, your HTML output reads:

        <html>
        <h1>Hello, my name is David Johnson</h1>
        </html>

        Cheers,
        NC

        Comment

        • Nikolai Chuvakhin

          #19
          Re: Including html files

          nc@iname.com (Nikolai Chuvakhin) wrote in message
          news:<32d7a63c. 0406241520.32b5 21dd@posting.go ogle.com>...[color=blue]
          >
          > Let's say you have a file 'intro.htm':
          >
          > <html>
          > <h1>Hello, my name is $name</h1>
          > </html>
          >
          > Then, you have this script:
          >
          > $name = 'David Johnson';
          > $content = '$newcontent = "' .
          > str_replace('"' , '&quot;', file_get_conten ts('intro.htm') ) .
          > '";';
          > eval($content);
          > echo $newcontent;
          >
          > Voila, your HTML output reads:
          >
          > <html>
          > <h1>Hello, my name is David Johnson</h1>
          > </html>[/color]

          On a second thought, there's a more elegant (yet still conceptually
          convoluted) solution:

          $name = 'David Johnson';
          eval('echo "' .
          str_replace('"' , '&quot;', file_get_conten ts('intro.htm') ) .
          '";');

          Cheers,
          NC

          Comment

          Working...