This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-01-24 15:04:04

muppetds
Scratcher
Registered: 2011-02-11
Posts: 1000+

PHP error

Probably something stupid but i cant figure out how to fix it this code..

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

Code:

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)


SCRATCH'S PARTLY INSANE RESIDENT 
http://internetometer.com/imagesmall/31691.pnghttp://bluetetrarpg.x10.mx/usercard/?name=muppetds

Offline

 

#2 2013-01-24 15:17:14

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: PHP error

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'; ?>).

Last edited by Magnie (2013-01-24 15:17:56)

Offline

 

#3 2013-01-24 15:29:08

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: PHP error

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  tongue )

/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)


nXIII

Offline

 

#4 2013-01-24 15:46:38

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: PHP error

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:

Code:

{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

 

#5 2013-01-25 08:42:20

muppetds
Scratcher
Registered: 2011-02-11
Posts: 1000+

Re: PHP error

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  big_smile


SCRATCH'S PARTLY INSANE RESIDENT 
http://internetometer.com/imagesmall/31691.pnghttp://bluetetrarpg.x10.mx/usercard/?name=muppetds

Offline

 

#6 2013-01-25 12:02:25

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: PHP error

muppetds wrote:

I use textwrangler BTW - allows you to edit the file directly on the server  big_smile

Make sure you back it up, though!

Last edited by nXIII (2013-01-25 12:02:43)


nXIII

Offline

 

#7 2013-01-25 16:59:28

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: PHP error

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  big_smile

Sorry, that's backwards, "Don't put PHP inside HTML, only HTML in PHP."

Offline

 

Board footer