PHP Version 5.2.8 jumping in and out of php & html?

  • Thread starter Thread starter aaron b
  • Start date Start date
A

aaron b

Guest
It has been a long time since I've touched php but i'm starting to get back into it. I remember I used to jump in and out of php and html using php tags such as <? and ?> however I do that now and it fails to process the php inside the tag I have to use <?php and ?>. Now I always start a php document off with <?php but after that I stick to using <? and ?>. Here is an example:

<?php

$today = date("F j, Y, g:i A");

?>
<html>

<head>

</head>

<body>
<p>It is now <? echo $today; ?></p>

</body>

</html>

In this example the <? echo $today; ?></p> won't work it has to be changed to <?php echo $today; ?></p>.

Did some research and wasn't able to find anything. Is this now common or is there a setting that can be changed so it will register php code after <? instead of always needing <?php ?

Thanks
 
yes, you will need to include the 'php' inside your tags. Another alternative is to not have any raw HTML inside your php script at all. You can just output it using php echo or print, which makes your code look neater. I had to resume a PHP project at work which somebody had started before me, and it has so much PHP and HTML interweven together, calling it 'spagetti code' would be an understatement. Eg:

<?php

$today = date("F j, Y, g:i A");

echo "
<html>

<head>

</head>

<body>
<p>It is now " . $today . " </p>

</body>

</html>";

that does the same thing as your above code, but using only PHP to do the dirty work. Using PHP tags inside HTML tags i found makes your code look messy.
 
Back
Top