kaseytraeger Posted January 26, 2004 Posted January 26, 2004 Hello out there all you TCH folk! I've got a basic PHP question. Does anyone know of any conflicts between PHP and XML or XHTML? I'm trying to update my web site to be XHTML compliant and I've discovered a problem. Here is the basic skeleton of one of my web pages. I've removed non-essential fluff (e.g., graphics, extra text, etc.) to make it easier to read. Even this simplified page will not display on my browser. All I see is a blank, white screen. <?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" xml:lang="en" lang="en"> <head> <title>Testing PHP inside XHTML</title> </head> <body> <p>Here is the clock -- <?php echo( date("g:i a") ); echo(", "); echo( date("d-M-Y") ); ?> </p> </body> </html> Can anyone tell me why this code will not run? I've tried various versions of the code, including removing the <?xml ...> line and the xmlns="http://... " statement from the document. Even removing these two items doesn't help. In fact, the only way I can get this page to display at all is to code it like this. <html> <head> <title>Testing PHP inside XHTML</title> </head> <body> <p> Here is the clock -- <?php echo( date("g:i a") ); echo(", "); echo( date("d-M-Y") ); ?> </p> </body> </html> I know there has to be some way to run PHP language inside an XHTML document, but I just don't know how to do it. Can someone help me out? Thanks! Kasey Quote
borfast Posted January 26, 2004 Posted January 26, 2004 I know this is a silly question but... does the file have a .php extension? Quote
kaseytraeger Posted January 27, 2004 Author Posted January 27, 2004 Hiya TCH-Raul Yes, the file does have a .php extension. I didn't clearly state that ... sorry for the confusion! Kasey Quote
krieser Posted January 27, 2004 Posted January 27, 2004 Have you tried it with the <!doctype> tag first, then the <?xml> tag, then your <html> tag? I thought the doctype came first, but maybe it doesn't matter... Kris Quote
krieser Posted January 27, 2004 Posted January 27, 2004 Sorry, ignore my previous post, but read this one.... http://forums.devshed.com/archive/5/2001/10/4/24769 Could this be part of the problem? Or is our php.ini file already configured this way? I noticed on one of the TCH pages it said we could not edit the php.ini... Hope this helps somewhat. Kris Quote
borfast Posted January 27, 2004 Posted January 27, 2004 Well, I never heard of the <?xml ....> declaration messing up PHP, even with short tags on... PHP should be looking *just* for <? or <?php, not <?somethingelse. But give it a try, remove the <?xml ...> declaration from the top of the file. I'm not sure it will work but you never know... Quote
wigoweb Posted January 27, 2004 Posted January 27, 2004 Not sure if this will help, but I copied and pasted your code into two different files and posted them both here: http://wigoweb.com/test/ You can try them. They both display the following text: Here is the clock -- Neither one actually displays any of the php you have listed. However, that may be due to my just getting started with php and probably not having it all set up correctly yet. But, I did not get a blank white page for either of the two files you provided. Quote
natimage Posted January 27, 2004 Posted January 27, 2004 (edited) I think the very top <?xml line is the one to change. The following code works for me: ><?php echo "<?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"> <head> <title>Testing PHP inside XHTML</title> </head> <body> <p>Here is the clock -- <?php echo( date("g:i a") ); echo(", "); echo( date("d-M-Y") ); ?> </p> </body> </html> Here's a link to the working page. Edited January 27, 2004 by natimage Quote
!!blue Posted January 27, 2004 Posted January 27, 2004 I'll have to implement that across my site. I've noticed that in my (minimal-use-of) php pages, all I could have was the doctype. No <?xml version=... and no <html xmlns="http://www.w3.org/1999/xhtml">. I figured that as long as my pages validated, that they were ok. But if I can add them back in, then cool :Nerd: later, !!blue Quote
borfast Posted January 27, 2004 Posted January 27, 2004 (edited) Tracy is right, that's the solution for the problem. I've used it countless times but my brain was probably on vacation, since I didn't remember it Edited January 27, 2004 by TCH-Raul Quote
natimage Posted January 27, 2004 Posted January 27, 2004 Thanks, Robert...but I owe that one to DWMX! It showed me the answer. Quote
kaseytraeger Posted January 27, 2004 Author Posted January 27, 2004 I want to say thank you to everyone for spending so much time helping me with this code. Big thanks to Tracy -- your suggestion fit the bill. The code runs -- yaaaay! So what was the deal with this? Is it conflicting processors (e.g., PHP processor trying to run an XML directive?) I hadn't heard of that before, but I guess if they both use the same <? symbol to declare the start of a sequence of code to be processed, then that would make sense. Thanks again everyone! Kasey Quote
Lianna Posted January 28, 2004 Posted January 28, 2004 Watch out Big Boys, Tracy's makin' a name for herself! Quote
natimage Posted January 28, 2004 Posted January 28, 2004 I'm currently unemployed (by my own will)...so I figure I ought to do something valuable with my time!!!! Nevermind the 3 or so websites waiting patiently for me to tend them... Quote
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.