Reputation: 21
I'm trying to call another php page without having one after the other.
I have pages a
and b
:
a.php
contains:
<html a page tags>
<?php echo "i'm a.php"; ?>
</html a page tags>
b.php
contains:
<html b page tags>
<?php
echo "i'm b.php";
include '../a.php';
?>
</html b tags>
When b.php
is run, it displays:
<html b page tags>
i'm b.php
<html a page tags>
i'm a.php
</html a page tags>
</html b tags>
You can see html tags from both a
and b
, one after the other.
Instead, when b.php
is run it should display only the text within a
's html tags. I.e., the output should be:
<html b page tags>
i'm b.php
i'm a.php
</html b tags>
Upvotes: 0
Views: 9859
Reputation: 186
Maybe a bit late :
I use echo file_get_contents(" URL ");
this shows only the output, if the site is a script , this script is run on the remote server.
Upvotes: 0
Reputation: 21
Thanks, I used header... I was missing something you have to put the php tag first before the html
<html>
</html>
<?php
//this will NOT work, the browser received the HTML tag before the script
header( 'Location: http://www.yoursite.com/new_page.html' ) ;
?>
As indicated here: http://php.about.com/od/learnphp/ht/phpredirection.htm
Upvotes: 0
Reputation: 1181
nice question :)
a.php
<html a page tgas>
<?php echo "i'm a.php"; ?>
</html a page tgas>
b.php
<html b page tags>
<?php
echo "i'm b.php";
?>
</html b tags>
<?php
require'../a.php'; // incase it doesnt execute it will give you error telling WHY??
?>
It will keep both the page tag intact and will give you the output as you want..
on clicking b.php
<html b page tags>
i'm b.php
</html b tags>
<html a page tags>
i'm a.php
</html a tags>
Upvotes: 0
Reputation: 374
If you don't need a.php to run by itself, just remove html tags from a.php.
If you want a.php and b.php can run separately, you can do it like this.
a.php
<?php if (isset($being_included)): ?>
<html a page tags>
<? endif; ?>
<?php echo "i'm a.php"; ?>
<?php if (isset($being_included)): ?>
</html a page tags>
<? endif; ?>
b.php
<html b page tags>
<?php
echo "i'm b.php";
$being_included = true;
include '../a.php';
?>
</html b tags>
Hope it helps.
Upvotes: 0
Reputation: 6905
You don't need to put HTML
tag in a.php if it's always included. meaning this:
a.php
<?php echo "i'm a.php"; ?>
b.php
<html b page tags>
<?php
echo "i'm b.php";
include '../a.php';
?>
</html b tags>
html output:
<html b page tags>
i'm b.php
i'm a.php
</html b tags>
Upvotes: 2