spazmatic Posted May 7, 2009 Share Posted May 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157159-basic-php-problem/ Share on other sites More sharing options...
sKunKbad Posted May 7, 2009 Share Posted May 7, 2009 Show more code. Quote Link to comment https://forums.phpfreaks.com/topic/157159-basic-php-problem/#findComment-828116 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Is there a difference between getting the data, then echoing and just including the file? Quote Link to comment https://forums.phpfreaks.com/topic/157159-basic-php-problem/#findComment-828122 Share on other sites More sharing options...
sKunKbad Posted May 7, 2009 Share Posted May 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157159-basic-php-problem/#findComment-828130 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 echo-ing will also put the info where you put the line. So there's no difference. Quote Link to comment https://forums.phpfreaks.com/topic/157159-basic-php-problem/#findComment-828139 Share on other sites More sharing options...
spazmatic Posted May 7, 2009 Author Share Posted May 7, 2009 Hmm anyone want to hop on my server and see if they can figure it out? i'll paypal you $10. It shouldn't be too difficult. Message me if you're interested. Quote Link to comment https://forums.phpfreaks.com/topic/157159-basic-php-problem/#findComment-828151 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Show more code. If you want to give away $10, go for it, but you can just show us more code. Quote Link to comment https://forums.phpfreaks.com/topic/157159-basic-php-problem/#findComment-828155 Share on other sites More sharing options...
spazmatic Posted May 7, 2009 Author Share Posted May 7, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/157159-basic-php-problem/#findComment-828207 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 You don't want that. You'll be messing up the HTML layout. You'll end up with 2 head tags and 2 body tags. Quote Link to comment https://forums.phpfreaks.com/topic/157159-basic-php-problem/#findComment-828266 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.