simi_id Posted June 11, 2011 Share Posted June 11, 2011 Hi, I have a.php .. with head and body, in head I have a.css which applies only to a.php In b.php I will have also head and body but b.css which I want to apply only to b.php, and to include a.php, but I have to add as well a.css into b.php, else it's not working. How can I have to separate files a.php with a.css and b.php with b.css and just to include them in c.php using just include and nothing more ? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/239059-php-include-function/ Share on other sites More sharing options...
freelance84 Posted June 11, 2011 Share Posted June 11, 2011 Hi, I have a.php .. with head and body, in head I have a.css which applies only to a.php In b.php I will have also head and body but b.css which I want to apply only to b.php, and to include a.php, but I have to add as well a.css into b.php, else it's not working. How can I have to separate files a.php with a.css and b.php with b.css and just to include them in c.php using just include and nothing more ? Thanks a.php contains: <head> <link href="a.css" rel="stylesheet" type="text/css" /> </head> <body></body> b.php contains: <head> <link href="a.css" rel="stylesheet" type="text/css" /> <link href="b.css" rel="stylesheet" type="text/css" /> </head> <body></body> But you also want to include a.php in b.php? Quote Link to comment https://forums.phpfreaks.com/topic/239059-php-include-function/#findComment-1228315 Share on other sites More sharing options...
simi_id Posted June 11, 2011 Author Share Posted June 11, 2011 a.php contains: <html> <head> <link href="a.css" rel="stylesheet" type="text/css" /> </head> <body>content a</body> </html> b.php contains: <html> <head> <link href="b.css" rel="stylesheet" type="text/css" /> </head> <body>content b</body> </html> c.php to contain only: <html> <head> <!-- no more css included in head each included file to use it's own css style included in their head section --> </head> <body> <?php require("a.php"); ?> <?php require("b.php"); ?> </body> </html> the ideea is that in the final document just to include files worked alone, not to be necessary to include css styles, and to mess one with another. Quote Link to comment https://forums.phpfreaks.com/topic/239059-php-include-function/#findComment-1228317 Share on other sites More sharing options...
freelance84 Posted June 11, 2011 Share Posted June 11, 2011 I'm not sure i know what your trying to achieve... Are you trying to get c.php to display a.php or b.php depending on some user action? Or are you wanting to house one html page within another? Quote Link to comment https://forums.phpfreaks.com/topic/239059-php-include-function/#findComment-1228320 Share on other sites More sharing options...
simi_id Posted June 11, 2011 Author Share Posted June 11, 2011 No. It's just for a simple web page. I want to develop all content in independent pages, like menu.php, content.php, footer.php, and so on ... and then just to place them in one single file. What I want is that single file where all are included to not require to add css in head. Each file included to use it's own css already defined in it own head. Quote Link to comment https://forums.phpfreaks.com/topic/239059-php-include-function/#findComment-1228332 Share on other sites More sharing options...
kenrbnsn Posted June 11, 2011 Share Posted June 11, 2011 Unless you're using frames, this idea will create an HTML file with improper markup, i.e. an HTML file can not have more than one <html></html>, <head></head>, and <body></body> section. Ken Quote Link to comment https://forums.phpfreaks.com/topic/239059-php-include-function/#findComment-1228338 Share on other sites More sharing options...
jcbones Posted June 11, 2011 Share Posted June 11, 2011 //text files in valid HTML markup. $head = file_get_contents('head.txt'); $menu = file_get_contents('menu.txt'); $content = file_get_contents('content.txt'); $footer = file_get_contents('footer.txt'); //php files with valid syntax, and variables already set. include 'head.php'; include 'menu.php'; include 'content.php'; include 'footer.php'; //using a heredoc to build the page. echo <<<HEREDOC <html> <head> {$head} </head> <body> <div id="menu">{$menu}</div> <div id="content">{$content}</div> <hr /> <div id="footer">{$footer}</div> </body> </html> HEREDOC; Quote Link to comment https://forums.phpfreaks.com/topic/239059-php-include-function/#findComment-1228340 Share on other sites More sharing options...
wildteen88 Posted June 11, 2011 Share Posted June 11, 2011 EDIT beaten to it You do not need to add the basic html structure for each page that is included. Only the html,head,body tags should be present within the parent file (c.php) that is including the files Here is an example of how to setup your files Index.php - contains the basic page structure <html> <head> <link href="main.css" rel="stylesheet" type="text/css" /> <link href="menu.css" rel="stylesheet" type="text/css" /> <link href="content.css" rel="stylesheet" type="text/css" /> <link href="footer.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Your title</h1> <?php require("menu.php"); ?> <?php require("content.php"); ?> <?php require("footer.php"); ?> </body> </html> menu.php contains only html for the menu <div id="menu"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> </div> content.php only the html to display the contents <div id="content"> <h2>Content Title</h2> <p>Your content here</p> </div> footer.php only the html for the footer <div id="footer"> <h4>Your footer here</h4> </div> Quote Link to comment https://forums.phpfreaks.com/topic/239059-php-include-function/#findComment-1228341 Share on other sites More sharing options...
simi_id Posted June 11, 2011 Author Share Posted June 11, 2011 Thanks guys, nice community in here. I finaly choosed the last solution to implement. Initialy I wanted that that menu.css to be in menu.php and so on, but I understood that there can be only 1 header even I include 1 file there can't be 2 headers only if I do frames if this is correct. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/239059-php-include-function/#findComment-1228389 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.