Jump to content

Recommended Posts

I'm new to php and i'm just making a simple site. I have the index.php with the site layout and menu and then the content in another php file.

 

I am using this code in the content.php to display the layout.

 

      <?php

 

// set file to read

$content = 'index.php' ;

 

// read file into string

$data = file_get_contents($content) or die('Could not read file!');

// print contents

echo $data;

?>

 

The only problem is the content is displaying underneath the site layout. How can i get the content to display inside the layout? I tried placing the php code in different areas in content.php but i cant get the two to blend together. Any help would be greatly appreciated. Thank you.

Link to comment
https://forums.phpfreaks.com/topic/157159-basic-php-problem/
Share on other sites

It depends on what the included file is doing, and how you are "getting" the data.

 

I think in your case you could just use:

 

echo(file_get_contents('index.php'));

 

or

 

include 'index.php';

 

but this will show the contents of index.php exactly where you have put this in the code. So if you need this content in a specific spot, use this code there.

Link to comment
https://forums.phpfreaks.com/topic/157159-basic-php-problem/#findComment-828130
Share on other sites

So basically i want to open content.php and have the layout and menu (index.php) open with it.

 

Heres index.php with the menu and layout

<head>

<title>Title</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="style3.css" rel="stylesheet" type="text/css" />

    <style type="text/css">

<!--

.style1 {

color: #FFFFFF;

font-size: 16px;

}

-->

    </style>

</head>

<body>

 

  <div id="wrapper">

      <div id="inner">

          <div id="header">

              <h1> </h1>

              <!-- end nav -->

          <a href="http://www.google.com"><img src="images/headerdg.jpg" width="844" height="145" /></a></div>

          <!-- end header -->

          <dl id="browse">

              <dt>Site</dt>

              <dd class="first"><a href="http://www.google.com">menu option</a></dd>

              <dd><a href="http://www.google.com">menu option</a></dd>

              <dd><a href="http://www.google.com">menu option</a></dd>

              <dd><a href="http://www.google.com">menu option</a></dd>

              <dd class="menuend"> </dd>

                            <dt>Menu</dt>

              <dd class="first"><a href="http://www.google.com">menu option</a></dd>

              <dd><a href="http://www.google.com">menu option</a></dd>

              <dd><a href="http://www.google.com">menu option</a></dd>

              <dd class="menuend"> </dd>

           

                       

              <dt>Menu</dt>

              <dd class="first"><a href="http://www.google.com">menu option</a></dd>

              <dd><a href="http://www.google.com">menu option</a></dd>

              <dd><a href="http://www.google.com">menu option</a></dd>

              <dd class="menuend"> </dd>

             

             

    </dl>

***This is where i need content.php to be when content.php is opened*****

<table height="25" border="0">

  <tr>

    <td> 

   

    </td>

  </tr>

</table>

 

 

        <!-- end body -->

         

        <div class="clear"></div>

          <div id="footer">

         

<a href="http://www.google.com">©2009</a>

             

               

              <div id="footnav">

             

            <a href="http://www.google.com">Legal</a> | <a href="http://www.google.com">Privacy Policy</a>              </div><!-- end footnav -->

          </div><!-- end footer -->

      </div><!-- end inner -->

     

  </div>

<!-- end wrapper -->

</body>

</html>

 

Heres content.php

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>title</title>

 

 

 

</head>

<body>

 

            <?php

 

echo(file_get_contents('index.php'));

 

?>

 

      <table width="600" border="0" class="table1">

  <tr>

    <td>

    <p align="center"><strong>Content</strong></p>

    <p align="center"> </p>

    <p>Blablablablablablablablablablablabla</p></td>

  </tr>

</table>

 

 

 

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/157159-basic-php-problem/#findComment-828207
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.