executing a php file within another php file with include()
Posted: Sat Dec 18, 2010 11:29 am
For future reference, please enclose PHP code within tags {syntax=php ] and [/syntax ] (without the spaces) to make your post readable, as I have done for you below. Use the "PHP Code" button at the top of the box where you are entering your post. Thank you.
Hello there,
I am learning slowly to create dynamic pages with php and I have a page called index.php in which I want to include the content of another page (called php.php).
It works well so far, I have the content of php.php displayed but then is my problem.
The file php.php contains a piece of (basic) php code that splits a word in 2 and when I execute it (it basically works using a GET function), I have the result displayed on the page generated by php.php (I think because the action is precisely php.php) and not inside my index.php page.
Here are the codes for the index.php:
and the one of php.php:
I don´t know how to have the php.php executing itself inside the index.php page.
Hello there,
I am learning slowly to create dynamic pages with php and I have a page called index.php in which I want to include the content of another page (called php.php).
It works well so far, I have the content of php.php displayed but then is my problem.
The file php.php contains a piece of (basic) php code that splits a word in 2 and when I execute it (it basically works using a GET function), I have the result displayed on the page generated by php.php (I think because the action is precisely php.php) and not inside my index.php page.
Here are the codes for the index.php:
Code: Select all
<html>
<table width='70%' align='center'>
<tr>
<td>
<h1>My web page</h1>
</td>
</tr>
</table>
<table width='70%' align='center'>
<tr>
<td width='20%'>
<a href='index.php'>Home</a><br>
<a href='index.php?page=newpage'>Tutorials</a>
</td>
<td width='80%'>
<?php
if (!isset($_GET['page']))
{
include('php.php');
}
else
{
$page = $_GET['page'];
include("inc/".$page.".php");
}
?>
</td>
</tr>
</table>
</html>Code: Select all
<html>
<form action="php.php" method="GET">
<input type="text" name="fullname">
<input type="submit" value="Split">
</form>
<?php
$firstname = "";
$lastname = "";
if(!isset($_GET['fullname']))
{
$_GET['fullname'] = "undefine";
}
else
{
$fullname = $_GET['fullname'];
$firstnamedone = false;
$len = strlen($fullname);
if ($fullname)
{
for ($x=0;$x<=$len;$x++)
{
if (mb_substr($fullname,$x,1)!=" " && $firstnamedone == false)
{
$firstname = $firstname.mb_substr($fullname,$x,1);
}
else
{
$firstnamedone = true;
$lastname = $lastname.mb_substr($fullname,$x,1);
}
}
$lastname = substr($lastname,1,($len)-1);
echo "
<input type='text' value='$firstname'>
<input type='text' value='$lastname'>";
}
else
{
echo "Please enter a name, dog.";
}
}
?>
</html>