Forum Moderators: coopster

Message Too Old, No Replies

Newbie PHP Question

         

john_m

10:39 am on Apr 27, 2005 (gmt 0)

10+ Year Member



Hi, I'm totally new to PHP, and inevitably I'm having a few problems converting a HTML page to PHP
First of all is the DTD. I code in XHTML and by having this as the DTD I get a blank page:

<?xml version="1.0" encoding="iso-8859-1"?>
<!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" xml:lang="en" lang="en">

Once I remove the top tag and just have <head> without the xmlns attribute, it works fine. I don't really care whether I have the DTD normal or not but why does this interfere with the display of a PHP page? Is it because of the "<?"

Once I do that, the page displays with no stylesheet, even though it's in my head tag and would otherwise work fine in HTML. Please help me, I'm totally lost

kumarsena

11:32 am on Apr 27, 2005 (gmt 0)

10+ Year Member



can u post the whole html source code from start up to <body>...

jatar_k

6:21 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it will be the xml tag killing it I am guessing, as it confuses the parser

$xmltag = '<?xml version="1.0" encoding="iso-8859-1"?>';
echo $xmltag;

that should work as then the php parser isn't trying to figure out the <?xml

patrickrock

6:24 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



why is everyone suddenly starting to put these xml declarations at the top of their pages?

ergophobe

8:49 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



These might answer the last question


An XML declaration is not required in all XML documents; however XHTML document authors are strongly encouraged to use XML declarations in all their documents. Such a declaration is required when the character encoding of the document is other than the default UTF-8 or UTF-16 and no encoding was determined by a higher-level protocol.

-- from [w3.org...]


Historically, the character encoding of an HTML document is either specified by a web server via the charset parameter of the HTTP Content-Type header, or via a meta element in the document itself. In an XML document, the character encoding of the document is specified on the XML declaration (e.g., <?xml version="1.0" encoding="EUC-JP"?>).

-- [w3.org...]


Because XHTML 1.0 is based on XML, it is common to add an XML declaration at the beginning of the markup, even if it is served as HTML.

--http://www.w3.org/International/articles/serving-xhtml/#declaration

john_m

9:46 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



Here's the HTML up to the body without the extra DTD tags:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Us</title>
<link rel="stylesheet" type="text/css" href="../contact.css" media="all" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>

Like I mentioned, this would work fine in HTML, even without putting it on the server, Frontpage shows it without any CSS applied to it. The only PHP on the page is a contact form.

coopster

2:40 am on Apr 28, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, john_m.

Your issue is with the PHP short_open_tag [php.net]. Turn it off or echo the declaration as jatar_k mentioned and you'll be off and running.

PHP Basic syntax [php.net] and the rest of the tutorial will be an enlightening read -- go get 'em.

john_m

6:55 am on Apr 28, 2005 (gmt 0)

10+ Year Member



Thanks for that- it works fine now. The CSS not showing was traced to a missing '}' in the CSS file, which is pretty bulky and took ages of searching. Don't you just hate when that happens? :) Anyway, thank you all for your help. I'll definitely get into reading more on PHP.