Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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...

Posted

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.

Posted (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 by natimage
Posted

 

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

Posted (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 :D

Edited by TCH-Raul
Posted

:D 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

<_<

Posted

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... :blink:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...