Probably something stupid but i cant figure out how to fix it this code..
<html> <head> <title>Cycling Calender</title> </head> <body> <?php $my_t=getdate(date("U")); print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]"); <table border="1"px> <--------------------THIS IS LINE 13 <th> print("$my_t[month]"); </th> <tr> <td> Monday </td> <td> Tuesday </td> <td> Wednesday </td> <td> Thursday </td> <td> Friday </td> <td> Saturday </td> <td> Sunday </td> </table> </body> </html> ?>
The error is
Parse error: syntax error, unexpected '<' in /home/a4013156/public_html/Index.html on line 13
Help please...
Last edited by muppetds (2013-01-24 15:06:20)
Offline
That is one of the reasons I discourage mixing of HTML and PHP (<p><?php echo 'hi'; ?></p> for example).
This should fix it:
<html> <head> <title>Cycling Calender</title> </head> <body> <?php $my_t=getdate(date("U")); print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]"); ?> [color=red]<table border="1px">[/color] <th> <?php print("$my_t[month]"); ?> </th> <tr> <td> Monday </td> <td> Tuesday </td> <td> Wednesday </td> <td> Thursday </td> <td> Friday </td> <td> Saturday </td> <td> Sunday </td> </table> </body> </html>
Make sure that the HTML and PHP are well defined (and possibly use a syntax highlighter, Notepad++ is good). Don't put HTML inside PHP (unless it's an echo/print or PHP commands inside HTML (unless they are inside <?php echo 'commands here'; ?>).
Last edited by Magnie (2013-01-24 15:17:56)
Offline
Magnie wrote:
That is one of the reasons I discourage mixing of HTML and PHP (<p><?php echo 'hi'; ?></p> for example).
How do you manage that? In order to get output, you either have to:
1) put <?php?> tags in HTML; or
2) echo HTML tags in PHP
Echoing HTML from PHP is kinda icky, so I usually go with 1).
I think I understand what you mean, though—I wrote a framework that lets me do something like this: (Yeah, I know it's a total copy of Django )
/app/hello_world/views.php
<?php
$hello_world = function () {
return render_template('hello_world/hello_world.php', array(
'message' => 'Hello, World!',
'log' => array(
'Example 1',
'Example 2',
),
));
};
/app/hello_world/templates/hello_world.php
<?php $extend('hello_world/base.html')?>
<?php $block('content')?>
<h1>Hello, World!</h1>
<p><?=htmlspecialchars($message)?></p>
<h1>Log</h1>
<?php foreach ($log as $item):?>
<div><?=htmlspecialchars($item)?></div>
<?php endforeach?>
<?php $endblock()?>
It helps one separate presentation (templates) from business logic (views).
P.S. <?=?> is not considered a short tag anymore, and is always enabled, so you can feel free to use <?=…?> as a shortcut for <?php echo …?>; it helps make templates more readable.
Last edited by nXIII (2013-01-24 15:29:56)
Offline
nXIII wrote:
Magnie wrote:
That is one of the reasons I discourage mixing of HTML and PHP (<p><?php echo 'hi'; ?></p> for example).
How do you manage that? In order to get output, you either have to:
1) put <?php?> tags in HTML; or
2) echo HTML tags in PHP
I mean mixing PHP inside HTML rather than putting HTML inside PHP (echo, $variables, etc). I think it gets really messy if you don't know exactly what you are doing. I'll admit I've started doing a little of it, but only for really large chunks of HTML code (CSS I just put into a .css file) where inserting PHP isn't needed. The start of a page for example:
{doctype} <html> <head> <?php //PHP code here ?> </body> </html>
If you are using an array of items, you may as well just generate the HTML for it instead.
Offline
Magnie wrote:
That is one of the reasons I discourage mixing of HTML and PHP (<p><?php echo 'hi'; ?></p> for example).
This should fix it:Code:
<html> <head> <title>Cycling Calender</title> </head> <body> <?php $my_t=getdate(date("U")); print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]"); ?> [color=red]<table border="1px">[/color] <th> <?php print("$my_t[month]"); ?> </th> <tr> <td> Monday </td> <td> Tuesday </td> <td> Wednesday </td> <td> Thursday </td> <td> Friday </td> <td> Saturday </td> <td> Sunday </td> </table> </body> </html>Make sure that the HTML and PHP are well defined (and possibly use a syntax highlighter, Notepad++ is good). Don't put HTML inside PHP (unless it's an echo/print or PHP commands inside HTML (unless they are inside <?php echo 'commands here'; ?>).
Ok so rather than putting html inside php you put php inside html...
I use textwrangler BTW - allows you to edit the file directly on the server
Offline
muppetds wrote:
Magnie wrote:
That is one of the reasons I discourage mixing of HTML and PHP (<p><?php echo 'hi'; ?></p> for example).
This should fix it:Code:
<html> <head> <title>Cycling Calender</title> </head> <body> <?php $my_t=getdate(date("U")); print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]"); ?> [color=red]<table border="1px">[/color] <th> <?php print("$my_t[month]"); ?> </th> <tr> <td> Monday </td> <td> Tuesday </td> <td> Wednesday </td> <td> Thursday </td> <td> Friday </td> <td> Saturday </td> <td> Sunday </td> </table> </body> </html>Make sure that the HTML and PHP are well defined (and possibly use a syntax highlighter, Notepad++ is good). Don't put HTML inside PHP (unless it's an echo/print or PHP commands inside HTML (unless they are inside <?php echo 'commands here'; ?>).
Ok so rather than putting html inside php you put php inside html...
I use textwrangler BTW - allows you to edit the file directly on the server
Sorry, that's backwards, "Don't put PHP inside HTML, only HTML in PHP."
Offline