PHP adding include to a generated web page

10 replies
Any ideas on how to add an include code to generated web pages. I'd like to keep some text and features up to date on each generated page.

Say I generate a get file contents line in the generated web page then I can echo the new text on web pages previously generated as well.

Rick
#adding #generated #include #page #php #web
  • Profile picture of the author priyag chaudhary
    I hope it's works
    you can also place your JavaScript code into a separate file (with a . js extension), and call that file in your HTML document through the src attribute of the <script> tag.
    {{ DiscussionBoard.errors[11581900].message }}
  • Hi Rick,
    by just calling "echo file_get_contents("mygen_page.php");" should work. Whatever you have in mygen_page.php as a PHP code will be generated into HTML and then output to the parent caller (the echo you have).
    {{ DiscussionBoard.errors[11582427].message }}
  • Profile picture of the author Ragni Vallejo
    Hi Rick, sorry for this late reply I'm a new user but I would like to share a thought.

    I normally use php includes for the header, menus and footer of my web designs as to only make changes in those relevant files that get included throughout the poroject. I've save many countless hours when having to update these sections.

    I do it like this:

    include("header.php");

    as an example
    {{ DiscussionBoard.errors[11584595].message }}
    • Profile picture of the author hometutor
      Originally Posted by Ragni Vallejo View Post

      Hi Rick, sorry for this late reply I'm a new user but I would like to share a thought.

      I normally use php includes for the header, menus and footer of my web designs as to only make changes in those relevant files that get included throughout the poroject. I've save many countless hours when having to update these sections.

      I do it like this:

      include("header.php");

      as an example
      I do the same. What I was looking for and I'll give echo a try, is a way to add to include command itself to an autogenerated page so it could have the same flexibility as my hand made pages which have the include command.

      Rick
      {{ DiscussionBoard.errors[11585356].message }}
  • Profile picture of the author shapovalov085
    You did't provide your code example. I can suggest you have something like:
    Code:
    $output = 'Lorem ipsum ... dynamic content';
    echo $output;
    To add included file contents like mycontent.php to $output as string use this:
    Code:
    $output = 'Lorem ipsum ... dynamic content';
    ob_start();
    include('mycontent.php');
    $output .= ob_get_contents();
    ob_end_clean();
    echo $output;
    {{ DiscussionBoard.errors[11584875].message }}
  • Profile picture of the author hometutor
    I basically ended up making the whole php command line a var then placing the var in the page to be generated.

    Rick
    {{ DiscussionBoard.errors[11633309].message }}
  • Profile picture of the author peteranalytics
    You have to break out the "dynamic" content into its own file, and include it into the templates.
    {{ DiscussionBoard.errors[11635819].message }}
  • Profile picture of the author Justcare
    The include statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.

    Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.
    {{ DiscussionBoard.errors[11738982].message }}

Trending Topics