PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Ruud Hermans
Forum Newbie
Posts: 11 Joined: Tue Nov 28, 2006 8:33 pm
Post
by Ruud Hermans » Tue Nov 28, 2006 8:35 pm
I'm pretty new to PHP. Could some one tell me why this script refuses to work?
I get an output but it does not display the image nore the menu witch is published as a list. I don't understand why not sinds it all works fine when I save it as a html document.
Code: Select all
<? php
print "<html>
<head>
<style type=\"text/css\">
#menu {
padding:0;
margin:0;
height:2em;
list-style-type:none;
border-left:1px solid #bbb;
}
#menu li {
float:left;
width:7em;
height:2em;
line-height:2em;
border-right:1px solid #bbb;
position:relative;
text-align:center;
}
#menu li a, #menu li a:visited {
display:block;
text-decoration:none;
color:#000;
}
#menu li a span, #menu li a:visited span {
display:none;
}
#menu li a:hover {
border:0; /* needed to trigger IE */
color:#bbb;
}
#menu li a:hover span {
display:block;
width:5em;
height:2em;
text-align:center;
position:absolute;
left:-2px;
top:-3px;
color:#000;
cursor:pointer;
}
</style>
</head>
<body>
<table bgcolor=\"#FFFFFF\" width=\"100%\" height=\"17%\" border=\"0\">
<tr>
<td width=\"100%\" height=\"100%\" rowspan=\"1\" colspan=\"1\" background=\"images/bg_top.gif\"></td>
</tr>
<tr>
<td>
<ul id=\"menu\">
<li><a href=\"#nogo\">Home<span>Home</span></a></li>
<li><a href=\"#nogo\">Disclaimer<span>Disclaimer</span></a></li>
<li><a href=\"#nogo\">Restaurants<span>Restaurants</span></a></li>
<li><a href=\"#nogo\">Recepies<span>Recepies</span></a></li>
<li><a href=\"#nogo\">Dictioinary's<span>Dictioinary's</span></a></li>
<li><a href=\"#nogo\">Forums<span>Forums</span></a></li>
<li><a href=\"#nogo\">Statistics<span>Statistics</span></a></li>
</ul>
</td>
</tr>
</table>
</body>
</html>
";
?>
Last edited by
Ruud Hermans on Thu Nov 30, 2006 8:38 am, edited 2 times in total.
Ruud Hermans
Forum Newbie
Posts: 11 Joined: Tue Nov 28, 2006 8:33 pm
Post
by Ruud Hermans » Tue Nov 28, 2006 8:48 pm
evilchris2003 wrote: Where is the PHP?
I need to add it but I fisrt want this to work. At a later time I want the links to be displayed in a chosen language and for that I will be using PHP. This needs to become the header witch will be used in several files first.
Zoxive
Forum Regular
Posts: 974 Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan
Post
by Zoxive » Tue Nov 28, 2006 8:48 pm
To make things simpler for you you could try using
' ' to surround the html, or even..
Code: Select all
<?
print <<<HTML
<html>
<head>
<style type="text/css">
#menu {
padding:0;
margin:0;
height:2em;
list-style-type:none;
border-left:1px solid #bbb;
}
#menu li {
float:left;
width:7em;
height:2em;
line-height:2em;
border-right:1px solid #bbb;
position:relative;
text-align:center;
}
#menu li a, #menu li a:visited {
display:block;
text-decoration:none;
color:#000;
}
#menu li a span, #menu li a:visited span {
display:none;
}
#menu li a:hover {
border:0; /* needed to trigger IE */
color:#bbb;
}
#menu li a:hover span {
display:block;
width:5em;
height:2em;
text-align:center;
position:absolute;
left:-2px;
top:-3px;
color:#000;
cursor:pointer;
}
</style>
</head>
<body>
<table bgcolor="#FFFFFF" width="100%" height="17%" border="0">
<tr>
<td width="100%" height="100%" rowspan="1" colspan="1" background="images/bg_top.gif"></td>
</tr>
<tr>
<td>
<ul id="menu">
<li><a href="#nogo">Home<span>Home</span></a></li>
<li><a href="#nogo">Disclaimer<span>Disclaimer</span></a></li>
<li><a href="#nogo">Restaurants<span>Restaurants</span></a></li>
<li><a href="#nogo">Recepies<span>Recepies</span></a></li>
<li><a href="#nogo">Dictioinary's<span>Dictioinary's</span></a></li>
<li><a href="#nogo">Forums<span>Forums</span></a></li>
<li><a href="#nogo">Statistics<span>Statistics</span></a></li>
</ul>
</td>
</tr>
</table>
</body>
</html>
HTML;
?>
Then you don't have to mess with all the slashes..
Ruud Hermans
Forum Newbie
Posts: 11 Joined: Tue Nov 28, 2006 8:33 pm
Post
by Ruud Hermans » Tue Nov 28, 2006 8:52 pm
I tried how you published the code but at the end of it it also ouputs:
Why is this?
evilchris2003
Forum Contributor
Posts: 106 Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK
Post
by evilchris2003 » Tue Nov 28, 2006 8:53 pm
because after the closing </html> tag you have HTML:
simply remove it
Zoxive
Forum Regular
Posts: 974 Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan
Post
by Zoxive » Tue Nov 28, 2006 8:55 pm
Must have an error somewhere, i just coped it again, and it works fine
->
evilchris2003 wrote: because after the closing </html> tag you have HTML:
simply remove it
Thats there on purpose..
But it should not output when done correctly.
Ruud Hermans
Forum Newbie
Posts: 11 Joined: Tue Nov 28, 2006 8:33 pm
Post
by Ruud Hermans » Tue Nov 28, 2006 8:56 pm
evilchris2003 wrote: because after the closing </html> tag you have HTML:
simply remove it
I can't believe I should delete it but for some reason I can't make it stop displaying the php closingtag ?>.
evilchris2003
Forum Contributor
Posts: 106 Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK
Post
by evilchris2003 » Tue Nov 28, 2006 9:00 pm
ah sorry my mistake ive never done that before
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Nov 28, 2006 10:25 pm
Ruud Hermans wrote: <? php
There's a blank between <? and php
<? relies on
short_open_tag =on, the default php.ini sets short_open_tag=off.
There's no need to print such a large static html "string", you can enter,leave and re-enter the php block many times. Everything outside a php block is sent as-is to the client.
Code: Select all
<html>
<head>
<style type="text/css">
#menu {
padding:0;
margin:0;
height:2em;
list-style-type:none;
border-left:1px solid #bbb;
}
#menu li {
float:left;
width:7em;
height:2em;
line-height:2em;
border-right:1px solid #bbb;
position:relative;
text-align:center;
}
#menu li a, #menu li a:visited {
display:block;
text-decoration:none;
color:#000;
}
#menu li a span, #menu li a:visited span {
display:none;
}
#menu li a:hover {
border:0; /* needed to trigger IE */
color:#bbb;
}
#menu li a:hover span {
display:block;
width:5em;
height:2em;
text-align:center;
position:absolute;
left:-2px;
top:-3px;
color:#000;
cursor:pointer;
}
</style>
</head>
<body>
<table bgcolor="#FFFFFF" width="100%" height="17%" border="0">
<tr>
<td width="100%" height="100%" rowspan="1" colspan="1" background="images/bg_top.gif"></td>
</tr>
<tr>
<td>
<ul id="menu">
<li><a href="#nogo">Home<span>Home</span></a></li>
<li><a href="#nogo">Disclaimer<span>Disclaimer</span></a></li>
<li><a href="#nogo">Restaurants<span>Restaurants</span></a></li>
<li><a href="#nogo">Recepies<span>Recepies</span></a></li>
<li><a href="#nogo">Dictioinary's<span>Dictioinary's</span></a></li>
<li><a href="#nogo">Forums<span>Forums</span></a></li>
<li><a href="#nogo">Statistics<span>Statistics</span></a></li>
</ul>
</td>
</tr>
</table>
<?php echo date("F j, Y, g:i a"); ?>
</body>
</html>
Ruud Hermans
Forum Newbie
Posts: 11 Joined: Tue Nov 28, 2006 8:33 pm
Post
by Ruud Hermans » Wed Nov 29, 2006 9:06 am
volka wrote: There's a blank between <? and php
<? relies on
short_open_tag =on, the default php.ini sets short_open_tag=off.
There's no need to print such a large static html "string", you can enter,leave and re-enter the php block many times. Everything outside a php block is sent as-is to the client.
I knew the fist part so I also tried it using the <?php as opening tag.
However I get it displayed as php code without any tags but is this a good way ore should I avoid doing this?
evilchris2003
Forum Contributor
Posts: 106 Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK
Post
by evilchris2003 » Wed Nov 29, 2006 9:14 am
what he means is there is no need to have your whole page processed by the PHP
you just need to put it where you need it in the page
look at the botom of the script Volka posted theres only 1 line processed using PHP and the rest is processed as HTML
Ruud Hermans
Forum Newbie
Posts: 11 Joined: Tue Nov 28, 2006 8:33 pm
Post
by Ruud Hermans » Wed Nov 29, 2006 9:21 am
evilchris2003 wrote: what he means is there is no need to have your whole page processed by the PHP
you just need to put it where you need it in the page
look at the botom of the script Volka posted theres only 1 line processed using PHP and the rest is processed as HTML
Meaning I do not need to use any php opening ore closing tag when no php is inserted between it?