Page 1 of 1
Trivial help to a hopeless newbie
Posted: Mon Dec 15, 2008 10:39 am
by Bozack
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi,
I'm just started on PHP after a way too long time without using it. I have simply forgotten everything I ever learned. Can anyone tell me why the code
Code: Select all
function top($pagetitle,$pagewidth,$dir) {
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" >
<link rel=stylesheet type="text/css" href="'.$dir.'style.css">
<title>'.$pagetitle.'</title>
</head>
<body><div align=center><table width='.$pagewidth.'><tr><td>';
return;
}
results in the error
Parse error: parse error, unexpected T_FUNCTION in file on line line
?
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Re: Trivial help to a hopeless newbie
Posted: Mon Dec 15, 2008 11:27 am
by Reviresco
Get rid of
-- not needed (and the correct usage would be:
at any rate).
When quoting an error message, be sure to leave in the line number so we can see where the error occurred.
Re: Trivial help to a hopeless newbie
Posted: Mon Dec 15, 2008 11:29 am
by jaoudestudios
What line does it say the error is on?
I think it is your return. Because you are not returning anything, so either remove this line or return a value (i.e true/false)
Re: Trivial help to a hopeless newbie
Posted: Mon Dec 15, 2008 11:30 am
by Bozack
The line it complains about is the line where I start defining the function, so it's complaining already on the line with
Code: Select all
function top($pagetitle,$pagewidth,$dir) {
moreover, it still gives the same error when I have removed the return.
Re: Trivial help to a hopeless newbie
Posted: Mon Dec 15, 2008 11:31 am
by jaoudestudios
Whats on the previous line?
Can you post the few lines before too?
Re: Trivial help to a hopeless newbie
Posted: Mon Dec 15, 2008 11:35 am
by Bozack
The whole start of the document:
Code: Select all
<?php
/* name: top
description: The top of all pages
written by: Bozack
created: 2008/12/15
modified: 2008/12/15
pagetitle: Title of the page
pagewidth: Width of the table containing the page
dir: Position from root */
// $pagetitle = '...' This is the default page title of the index page
global $pagewidth;
$pagewidth = '600px'
function top($pagetitle,$dir) {
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" >
<link rel=stylesheet type="text/css" href="'.$dir.'style.css">
<title>'.$pagetitle.'</title>
</head>
<body><div align=center><table width='.$pagewidth.'><tr><td>';
return;
}
and it was complaining about line 17
Re: Trivial help to a hopeless newbie
Posted: Mon Dec 15, 2008 11:37 am
by Reviresco
Missing a semi-colon at the end of line 15.
Re: Trivial help to a hopeless newbie
Posted: Mon Dec 15, 2008 11:38 am
by Bozack
Argh, dammit, can't believe I didn't saw that! Thanks!

Re: Trivial help to a hopeless newbie
Posted: Mon Dec 15, 2008 3:46 pm
by cavemaneca
Also, why didn't you just do this?
Code: Select all
<?php
// other code
function top($pagetitle,$pagewidth,$dir) {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" >
<link rel=stylesheet type="text/css" href="<?php echo $dir; ?>/style.css">
<title><?php echo $pagetitle; ?></title>
</head>
<body><div align=center><table width="<?php echo $pagewidth; ?>"><tr><td>
<?php
}
?>
It seems simpler to me that way, and you don't have to worry about anything stupid like escaping.
EDIT: Thanks for pointing that out jaoudestudios. I forgot to echo the variables. The above should be fixed.
Re: Trivial help to a hopeless newbie
Posted: Mon Dec 15, 2008 4:03 pm
by jaoudestudios
cavemaneca...
<title>'.$pagetitle.'</title>
That would not work! Unless within php tags.
i.e.
Code: Select all
<title><?php echo $pagetitle; ?></title>
Re: Trivial help to a hopeless newbie
Posted: Tue Dec 16, 2008 12:23 am
by Bozack
Actually I didn't thought that you could go out of the <?php ... ?> tags within a function

But yes, that is much easier, and tidier
Re: Trivial help to a hopeless newbie
Posted: Tue Dec 16, 2008 2:02 am
by jaoudestudios
No problem cavemaneca - easy mistake, I know you were going for principle rather than completing the whole code.