Include HTML file as variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WBSKI
    New Member
    • Jun 2007
    • 3

    Include HTML file as variable

    Can I include a file as a variable without it showing on the page?

    What I want to do:

    Include an HTML file and adjust the links to make it work from a different folder.

    [PHP]$begin = "path to site root (hidden for security)";
    $end = "_bolGallerySta ticPage.html";
    $raw = include($begin. $row_Recordset1['url'].$end);
    $search = "./";
    $replace = $row_Recordset1['url'];
    $test = str_replace ($search, $replace, $raw);
    echo $test[/PHP]

    Currently I cant set the $raw variable and only the original code shows.

    Thanks from Russell!
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    Originally posted by WBSKI
    Can I include a file as a variable without it showing on the page?

    What I want to do:

    Include an HTML file and adjust the links to make it work from a different folder.

    [PHP]$begin = "path to site root (hidden for security)";
    $end = "_bolGallerySta ticPage.html";
    $raw = include($begin. $row_Recordset1['url'].$end);
    $search = "./";
    $replace = $row_Recordset1['url'];
    $test = str_replace ($search, $replace, $raw);
    echo $test[/PHP]

    Currently I cant set the $raw variable and only the original code shows.

    Thanks from Russell!
    What will be the value for this record set
    [PHP]$row_Recordset1['url'];[/PHP]

    Comment

    • WBSKI
      New Member
      • Jun 2007
      • 3

      #3
      Originally posted by ajaxrand
      What will be the value for this record set
      [PHP]$row_Recordset1['url'];[/PHP]
      Its site relative:

      /data/1/photos/other/

      It is the other folder where the page is included from.

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        As i think you can't assign include() and its parameter to a variable, because its a Control Structure.

        You may better try another way of making your script.

        Comment

        • WBSKI
          New Member
          • Jun 2007
          • 3

          #5
          Originally posted by ajaxrand
          As i think you can't assign include() and its parameter to a variable, because its a Control Structure.

          You may better try another way of making your script.

          I dont care how I load the file. Your point is, I cant set a file as a variable?

          Comment

          • ak1dnar
            Recognized Expert Top Contributor
            • Jan 2007
            • 1584

            #6
            Originally posted by WBSKI
            I dont care how I load the file. Your point is, I cant set a file as a variable?
            I think i went here and there since i couldn't understand your requiremet properly.
            Do you expecting to put someotherfile(o ther.html) contents to this script (this.php) without showing other.html contents inside this.php is that correct?
            Then you need to use str_replace for the coding that you get from other.html.

            Comment

            • ak1dnar
              Recognized Expert Top Contributor
              • Jan 2007
              • 1584

              #7
              Originally posted by ajaxrand
              As i think you can't assign include() and its parameter to a variable, because its a Control Structure.

              You may better try another way of making your script.
              Sorry for this post, you can assign file contents to a variable.
              [PHP]$_file = include('subdir/data/_bolGalleryStat icPage.html');[/PHP]

              Comment

              • ronnil
                Recognized Expert New Member
                • Jun 2007
                • 134

                #8
                doesn't include() force the browser to output immediately?

                normally for that type of function i use ob_get_contents ();

                [CODE=php]<?php
                $file = 'path/to/file.php'
                ob_start();
                include($file);
                $file_contents = ob_get_contents ();
                ob_end_clean();
                ?>[/CODE]

                now you have everything outputted and stored in $file_contents. Now you can peform replaces and such before echoing it.

                Comment

                • ak1dnar
                  Recognized Expert Top Contributor
                  • Jan 2007
                  • 1584

                  #9
                  If you are looking for something like ronnil said,For more info you can refer to this URL.

                  Comment

                  Working...