Mutley Posted January 7, 2007 Share Posted January 7, 2007 I have 2 files, my index.php and a test.php, I want to include test.php into the index but it's a little more complicated than that (because the way my htaccess/variables are set up).Is it possible so if I go to mysite.com/test.php it includes index.php and places the code from test.php [b]inside[/b] the index.php (so I don't have to split it into 2 files).I hope that makes sense. ??? Link to comment https://forums.phpfreaks.com/topic/33191-reverse-include/ Share on other sites More sharing options...
onlyican Posted January 7, 2007 Share Posted January 7, 2007 when using PHP include and require, it adds the content of the documents togetherso if you want to go to test.php, and have the contents from index.phpyou want something like[b]index.php[/b][code]This is my Index Page[/code][b]test.php[/b][code]<?php require("index.php");?><br />and This is my Test Page[/code][b]Output[/b][quote]This is my Index Pageand This is my Test Page[/quote]If this is not what you mean, please explain more Link to comment https://forums.phpfreaks.com/topic/33191-reverse-include/#findComment-154961 Share on other sites More sharing options...
Mutley Posted January 7, 2007 Author Share Posted January 7, 2007 I understand that but what I want to do is this:index.php[code]This is line 1This is line 2This is line 3[/code]test.php[code]Here we are[/code][code]This is line 1Here we areThis is line 2This is line 3[/code]It includes the index.php in test.php then inserts the code in a specific part of the index.php that is included (somehow). Link to comment https://forums.phpfreaks.com/topic/33191-reverse-include/#findComment-154969 Share on other sites More sharing options...
trq Posted January 7, 2007 Share Posted January 7, 2007 Can't do it. Include simply includes the entire page wherever it is called. Simple. Link to comment https://forums.phpfreaks.com/topic/33191-reverse-include/#findComment-154972 Share on other sites More sharing options...
onlyican Posted January 7, 2007 Share Posted January 7, 2007 BUTYou can do something like[b]index.php[/b][code]$part_a = "Line 1Mbr />\n";$part_b = "Line2<br />\n";$part_b .= "line3<br />\n";[/code][b]Test.php[/b][code]require("index.php");echo $part_a;echo "Here we are<br />\n";echo $part_b;[/code] Link to comment https://forums.phpfreaks.com/topic/33191-reverse-include/#findComment-154973 Share on other sites More sharing options...
trq Posted January 7, 2007 Share Posted January 7, 2007 Even better would be to wrap the functionality of index.php into functions, then call them in whatever order you need to. Link to comment https://forums.phpfreaks.com/topic/33191-reverse-include/#findComment-154976 Share on other sites More sharing options...
Mutley Posted January 7, 2007 Author Share Posted January 7, 2007 Could you give an example of using functions? Will it effect how index.php works using functions around it? Link to comment https://forums.phpfreaks.com/topic/33191-reverse-include/#findComment-155029 Share on other sites More sharing options...
trq Posted January 7, 2007 Share Posted January 7, 2007 [quote]Will it effect how index.php works using functions around it[/quote]Yes.index.php[code]<?php function a() { echo "this is a"; } function b() { echo "this is b"; } function c() { echo "this is c"; }?>[/code]test.php[code]<?php include "index.php"; a(); echo "hello"; b(); c();?>[/code] Link to comment https://forums.phpfreaks.com/topic/33191-reverse-include/#findComment-155032 Share on other sites More sharing options...
onlyican Posted January 7, 2007 Share Posted January 7, 2007 Explain to use what exactly you are trying to do.Do you want to use this as a sort of Templateand you want the page in the middle of the templateIf thats the case[b]inc_header.php[/b][code]<html><head><title>Website Title</title></head><body>[/code][b]inc_footer.php[/b][code]</body></html>[/code][b]Page[/b][code]<?phprequire("inc_header.php");?>My Website Content<?phprequire("inc_footer.php");?>[/code][code][/code] Link to comment https://forums.phpfreaks.com/topic/33191-reverse-include/#findComment-155033 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.