Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function and the 'include' statement 1

Status
Not open for further replies.

perlone

Programmer
May 20, 2001
438
US
Hello

I'm orginally a Perl programmer and starting a project in PHP. I have a question about the function statement. What I want to do is store all header info (such as the HTML) in a file called 'header.php' and retrieve those information using other PHP files. Here's an example:

header.php:
<?
function ($text, $title)
{
<HTML>
<TITLE>$title</TITLE>
<p align=&quot;center&quot;>$title</p>

<p align=&quot;left&quot;>$text</p>

</HTML>
}
?>

and in login.php, I have this:
<?php

include 'header.php';

header(&quot;SSSSSSS&quot;,&quot;SSS&quot;);

?>

However, it is not working. I was wondering if anyone could assist me on this. Thanks for your time. There is no Knowledge that is not power.
Age: 17
E-mail: projectnet01@yahoo.com
Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
Code:
include
is a function too, which you would have to call by
Code:
include('./header.php');
. Unlike Perl, the parenthisis aren't optional. //Daniel
 
I'm still getting the following errors:

Parse error: parse error in servers/m/php/header.php on line 6

Warning: Cannot add header information - headers already sent by (output started at /servers/m/php/header.php:6) in /servers/m/php/table_results.php on line 6


In header.php, I have this:
<?php

function header ($text, $title)
{

<html>

<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html; charset=iso-8859-1&quot;>
<title>$title</title>
</head>

<body bgcolor=&quot;#FFFFFF&quot;>

<p align=&quot;center&quot;><font size=&quot;2&quot; face=&quot;Arial&quot;><strong>$title</strong></font></p>

<p align=&quot;left&quot;><font size=&quot;2&quot; face=&quot;Arial&quot;>$text</font></p>
</body>
</html>
}


?>

Any clue? There is no Knowledge that is not power.
Age: 17
E-mail: projectnet01@yahoo.com
Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
What you want is this:
Code:
<?php

function myHeader ($text, $title)
{
?>
<html>

<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html; charset=iso-8859-1&quot;>
<title><?=$title?></title>
</head>

<body bgcolor=&quot;#FFFFFF&quot;>

<p align=&quot;center&quot;><font size=&quot;2&quot; face=&quot;Arial&quot;><strong><?=$title?></strong></font></p>

<p align=&quot;left&quot;><font size=&quot;2&quot; face=&quot;Arial&quot;><?=$text?></font></p>
</body>
</html>
<?php
}
?>
The function header is already defined in PHP, it outputs header information to the client. Therefore, you have to name your function something else. I chose myHeader, but you can change it to whatever you want.
Also, when you want to just print a bunch of HTML, it's easier to break out of PHP mode and switch to HTML mode. //Daniel
 
Thanks Daniel! It is working now :). Hmm... I tried without that required parenthisis and it worked fine though. There is no Knowledge that is not power.
Age: 17
E-mail: projectnet01@yahoo.com
Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top