Jump to content

Reverse include?


Mutley

Recommended Posts

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

when using PHP include and require, it adds the content of the documents together

so if you want to go to test.php, and have the contents from index.php

you 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 Page
and 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

I understand that but what I want to do is this:

index.php
[code]
This is line 1
This is line 2
This is line 3
[/code]

test.php
[code]
Here we are
[/code]

[code]
This is line 1
Here we are
This is line 2
This 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

[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

Explain to use what exactly you are trying to do.

Do you want to use this as a sort of Template
and you want the page in the middle of the template

If 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]
<?php
require("inc_header.php");
?>
My Website Content
<?php
require("inc_footer.php");
?>
[/code]
[code][/code]
Link to comment
https://forums.phpfreaks.com/topic/33191-reverse-include/#findComment-155033
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.