WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-03-2007, 07:40 AM
WebProWorld New Member
 

Join Date: Feb 2007
Posts: 3
Alice 888 RepRank 0
Default Question(s) for PHP Pros

I'm taking a PHP + mySQL class at school, and I wanted to ask some regular php coders out there about how you put php into a page.

I know a small amount of php, enough to make just a simple database driven site. Every tutorial that I've learned from just slaps the php in where it needs to be used. An example would be this:
CODE
<?php

$date = date("F d, Y H:i:s a");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head><title>Comm393: </title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<body>

<h1>Hello World</h1>
<center><?php echo("$date") ?></center>
</body></html>
__________________________________________________ _
[url=http://www.cheapstingybargains.com/]Buy.com Coupons[/ul] Intensive English Course
Reply With Quote
  #2 (permalink)  
Old 02-03-2007, 09:06 AM
bj's Avatar
bj bj is offline
WebProWorld 1,000+ Club
 

Join Date: Apr 2005
Location: Delaware Valley, PA
Posts: 1,186
bj RepRank 2bj RepRank 2
Default

A warning-- yes, certain calls can be placed where you need them, but putting certain calls in that will render BEFORE the doctype in a document that is meant to be served as xhtml will have all sorts of unintended consequences since it will kick all the browsers into quirks mode, which could, if your document is indeed an xhtml 1.0 transitional document, break rendering in IE for almost certain, and possibly break it in other browsers as well.
Reply With Quote
  #3 (permalink)  
Old 02-03-2007, 12:02 PM
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Cornwall, UK
Posts: 833
speed RepRank 1
Default

Just to add to bjs answer, in your example the PHP code is fine where it is however the white space between the ?> tag and the DOCTYPE will be sent to the browser and so will put IE into quirks mode.

You do need to watch where white space occurs.
__________________
TOLRA Micro Systems Limited US & UK Web Hosting with Continuous Data Protection
Web Directory 2 for 1 Offer : Web Directory Script
Reply With Quote
  #4 (permalink)  
Old 02-04-2007, 10:11 AM
DaveSawers's Avatar
WebProWorld Veteran
 

Join Date: Dec 2006
Location: Calgary, Alberta, Canada
Posts: 384
DaveSawers RepRank 1
Default

So, yes. Just "slap it in where it's needed".

There's no need to code the whole page in PHP. In fact, using PHP unecessarily can be a real pain at the design stage where you might still need to move things around.
__________________
Dynamic Software Development
www.activeminds.ca
Reply With Quote
  #5 (permalink)  
Old 02-14-2007, 05:14 PM
WebProWorld Pro
 

Join Date: Feb 2004
Location: England Baby!
Posts: 222
icb01co2 RepRank 0
Default

Erm, no dont just slap it where its needed!!

I believe that your question was only related to whether you can add your php before the DOCTYPE, which has been answered well here. Although, you have also touched upon another issue.

Think about when your small site becomes a larger project, eventually having your html and php mixed together will be a nightmare to debug. Your goal should be to find away to seperate your logic from your content. If your looking for a better way to structure your programs try searching on things like: Smarty templating engine, MVC architecture and OOP php.

If you get your head around these subjects making larger scale developments will become a whole lot easier.

Chris.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0