Web Hosting Talk







View Full Version : How do u include php file inside a html table that you are echoing ?


latheesan
08-15-2005, 06:18 PM
Basically, im doing a little check to see if someone is directly accessing my script, if so, warn them, otherwise echo the real content of the page like this

<?php

if (!defined('IN_SCRIPT')){
echo "Sorry, you can't access this page directly!";
}
else{

//The real content
echo "<table align=\"center\" border=\"0\" width=\"800\" height=\"300\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td width=\"800\" height=\"300\" align=\"left\" valign=\"top\" class=\"body\" bgcolor=\"#FFFFFF\">
<?php include ("file.php"); ?></td>
</tr>
</table>";
}

?>

as you can see, inside the table im trying to include a php file in there, but i cant seemed to be able to do this.

So, ho do you include a php file inside a table in html you are echoing?

Xenatino
08-15-2005, 07:34 PM
You have to terminate the echo, include the file then restart the echo:


<?php

if (!defined('IN_SCRIPT')){
echo "Sorry, you can't access this page directly!";
}
else{

//The real content
echo "<table align=\"center\" border=\"0\" width=\"800\" height=\"300\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td width=\"800\" height=\"300\" align=\"left\" valign=\"top\" class=\"body\" bgcolor=\"#FFFFFF\">";

include ("file.php");

echo "</td>
</tr>
</table>";
}

?>

latheesan
08-15-2005, 08:36 PM
Bravoo, nice suggestion.

haa, why didnt i think of this. lolz

Thanks Xenatino,

Dashbox
08-16-2005, 07:39 AM
Also, just a quick pointer. If you prefer nto to escape all of your \" within your echo, you can do it like this:


<?php
echo '<table border="0" cellpadding="0" cellspacing="0">'.
' <tr>'.
' <td>'.$some_content.'</td>'.
' </tr>'.
'</table>';
?>


etc...

gogocode
08-16-2005, 08:00 AM
Use PHP for what it was designed...


<?php
if (!defined('IN_SCRIPT'))
{
?>Sorry, you can't access this page directly!<?php
}
else
{
?>
<table>
<tr>
<td>
<?php include('yourfile') ?>
</td>
</tr>
</table>
<?php
}
?>


Also, looks like you might be including files specified on the URL, so make sure you check that those files should be included!