bananababe Posted May 20, 2009 Share Posted May 20, 2009 I set up a guestbook in php but it of course does work with the html doc type declaration I use for the other html pages since it confuses the browser. So I deleted the xml and doc type but when I try to validate I get lots of errors for this page. Is there a way around this? I read somewhere online that you can use javascript to get around this, but I tried using a <script> document.write(); and that didn't work. I am currently using the transitional doctype in the rest of my pages: <?xml version="1.0" encoding="UTF-8"?> <!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"> I also noticed that when I load the same php page in IE 7/8, the php page is not centered (like the rest of my pages) and some of my other css properties are not being accessed (though not all which is wierd). I've still got the external link to the css file in the header, so I suspect it has to do with the doctype missing, but maybe it is just IE Anyone know how to resolve this? Quote Link to comment https://forums.phpfreaks.com/topic/158946-solved-how-to-set-up-doctype-so-php-page-validates-with-w3c/ Share on other sites More sharing options...
bdmovies Posted May 20, 2009 Share Posted May 20, 2009 1. The doctype isn't affected by PHP, unless you are doing something strange in the PHP - why can't you just use the same doctype as everywhere else on your site. 2. Your page breaking in IE 7/8 is a problem with IE (most likely) not PHP, maybe your CSS needs some tweaking. Quote Link to comment https://forums.phpfreaks.com/topic/158946-solved-how-to-set-up-doctype-so-php-page-validates-with-w3c/#findComment-838300 Share on other sites More sharing options...
wildteen88 Posted May 20, 2009 Share Posted May 20, 2009 What issues are your facing when adding those lines to your script? Also in order for browsers to apply your CSS properly you need to provide a doctype. Otherwise you will experience unexpected behaviour. Quote Link to comment https://forums.phpfreaks.com/topic/158946-solved-how-to-set-up-doctype-so-php-page-validates-with-w3c/#findComment-838302 Share on other sites More sharing options...
bananababe Posted May 20, 2009 Author Share Posted May 20, 2009 If I include the doctype, this is what the browser displays: "Parse error: syntax error, unexpected T_STRING in /home4/allenski/public_html/guestbook.php on line 1" Quote Link to comment https://forums.phpfreaks.com/topic/158946-solved-how-to-set-up-doctype-so-php-page-validates-with-w3c/#findComment-838303 Share on other sites More sharing options...
wildteen88 Posted May 20, 2009 Share Posted May 20, 2009 You most probably have short_open_tag enabled and PHP is trying to parse this as PHP code: <?xml version="1.0" encoding="UTF-8"?> In which case you should echo that line to prevent this from happening <?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"; ?>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/158946-solved-how-to-set-up-doctype-so-php-page-validates-with-w3c/#findComment-838307 Share on other sites More sharing options...
bananababe Posted May 20, 2009 Author Share Posted May 20, 2009 thank you very much wildteen88! I am just getting into php - can you please tell me what a short_open_tag enabled means? I see you escaped the quotes with the backslash. FYI - I still got one error with your adjusted echo xml declaration and I figured out it was the extra ";" after \"UTF-8\"; bdmovies – wildteen88's fix solved my IE page layout problem Quote Link to comment https://forums.phpfreaks.com/topic/158946-solved-how-to-set-up-doctype-so-php-page-validates-with-w3c/#findComment-838328 Share on other sites More sharing options...
wildteen88 Posted May 20, 2009 Share Posted May 20, 2009 When the setting short_open_tag is enabled it allows you to use short hand syntax such as <? ?> instead of <?php ?> or <?='hello'?> instead of <?php echo 'hello'; ?> However this setting is now depreciated and is disabled by default. It is always best to use the full PHP syntax as this will allow your code to be more portable. Quote Link to comment https://forums.phpfreaks.com/topic/158946-solved-how-to-set-up-doctype-so-php-page-validates-with-w3c/#findComment-838333 Share on other sites More sharing options...
bananababe Posted May 20, 2009 Author Share Posted May 20, 2009 huh! thanks. my php code in the doc is surrounded by <?php ..... ?> but there are instances where it switches back to html and then uses the short tag when resuming php. Is the short tag enabled an option you code in php or is it a browser preference? thanks very much!! Quote Link to comment https://forums.phpfreaks.com/topic/158946-solved-how-to-set-up-doctype-so-php-page-validates-with-w3c/#findComment-838340 Share on other sites More sharing options...
wildteen88 Posted May 20, 2009 Share Posted May 20, 2009 short_open_tag is a PHP setting found within the main configuration file (php.ini). If you're on shared hosting it is more than likely you wont have access to this file. Quote Link to comment https://forums.phpfreaks.com/topic/158946-solved-how-to-set-up-doctype-so-php-page-validates-with-w3c/#findComment-838351 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.