simple php question, how do i pass value from a function into another?

This is in my index.php
<? include("body.php"); body("home"); ?>

As you can see its calling a function called "body" from a file called body.php
This is the body.php...
<? function body($pageaddress){
?>
     <? include("\"" ?> <? .$pageaddress. ?> <? .php"\""); ?>
<? } ?>

Can anyone point out where i've gone wrong? I'm very new to php programming.
Antonio KingIT ManagerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
nplibConnect With a Mentor Commented:
add this just to see if the variable is being passed
<?php
function body($pageaddress){
 echo $pageaddress;
 $html .= "<table>";
 $html .= "<tr>";
 $html .= "<td>";
 include("/".$pageaddress.".php");
 $html .= "</td>";
 $html .= "</tr>";
 $html .= "</table>";
 return $html;
}
?>

Open in new window

0
 
simonkinCommented:
Try this...
<?php
 
	function body($pageaddress) {
	
		include("\\" . $pageadress . ".php");
	
	}
	
?>

Open in new window

0
 
nplibCommented:
<?php
function body($pageaddress){
     include($pageaddress.".php"); ?>
}
?>
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
simonkinCommented:
Sorry...


<?php
 
	function body($pageaddress) {
	
		include($pageadress . ".php");
	
	}
	
?>

Open in new window

0
 
bestondoaCommented:
Hi Alan,

Try this instead of your current body function:

<?php function body($pageaddress){
      
      include("\.".$pageaddress.".php");
}
?>
0
 
nplibCommented:
unless you want the slashes, but in a url slashes go the other way.
and if you have a slash at the beginning of your address it symbolizes the root of the website
0
 
nplibCommented:
such as
<?php
function body($pageaddress){
     include("/".$pageaddress.".php"); ?>
}
?>

Open in new window

0
 
Antonio KingIT ManagerAuthor Commented:
sorry should make things a little clearer...
the function would actually look more like this...

<? function body($pageaddress){
?>
<table>
   <tr>
      <td>
         <? include("\"" ?> <? .$pageaddress. ?> <? .php"\""); ?>
      </td>
   </tr>
</table>
<? } ?>
0
 
nplibCommented:
do this

<?php
function body($pageaddress){
 $html .= "<table>";
 $html .= "<tr>";
 $html .= "<td>";
 include("/".$pageaddress.".php");
 $html .= "</td>";
 $html .= "</tr>";
 $html .= "</table>";
 return $html;
}
?>
 
 
then to use it
 
echo body("home");

Open in new window

0
 
Antonio KingIT ManagerAuthor Commented:
include(/.php) [function.include]: failed to open stream: No such file or directory in
0
 
steelseth12Connect With a Mentor Commented:
That will not work as expected because include will execute as soon as it is called you need something a bit more complex.
function body($pageaddress){
 ob_start();
 include($pageaddress.".php");
 $inc = ob_get_contents();
 ob_end_clean();
 $html .= "<table>";
 $html .= "<tr>";
 $html .= "<td>";
 $html .= $inc;
 $html .= "</td>";
 $html .= "</tr>";
 $html .= "</table>";
 return $html;
}

Open in new window

0
 
nplibCommented:
yes your right.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.