Help - Search - Members - Calendar
Full Version: Using PHP with XHTML
Pixel2Life Forum > Member Tutorials and Requests > Forum Tutorial Archives > Miscellaneous Tutorials
raenef
This may be common knowledge for those of you more experienced with PHP out there, however I racked my brain trying to figure out why my php scripts werent working correctly with my XHTML pages. Which is why I stopped learning PHP for a while. (Just starting now actually :-p)
So for those of you who are having trouble as well using XHTML with PHP, I present to you a short tutorial to make sure they work correctly together.

The problem is the very first line in a XHTML page.
CODE
<?xml version="1.0" encoding="iso-8859-1"?>

Using that in conjunction with your php includes, or other php code causes the page to error because PHP thinks that the <?xml... tag is PHP as well.

To fix:
Open your php.ini file and look for:
CODE
short_open_tag = On

and change it to:
CODE
short_open_tag = Off


Save and close it. Now in order to use php code; you must start with <?php... instead of the short tag <?...
However you should now be able to use PHP and XHTML together flawlessly.
Tudi
Heh I wanted to start learning PHP for some time, and I bet if i would have done it, I would've got stuck on this matter. Tnx for explaining this, it probably saved up a lot of my time.


By the way, since I'm such a PHP noob, could you explain a bit of the concept of working with includes? What are PHP includes exactly and how do I use them (or do they just reffer to including external php files to your HTML code)?

Also, do you know anything about SSi (Server Side Includes). I got advice from a lot of ppl to start using SSi for my websites, but none of them could explain the concept (see, they were just using templates that had SSI withing them).

Tnxy and sorry for the bother.
raenef
You're welcome. happy.gif Im glad it helped a bit, as I hope it helps others having the same problem.

Php includes can be used for many things. I use them for navigation, instead of writing links over and over and over again in each and every html/xhtml page. You can write them once and include them using php includes. More information can be gained from the tutorials found here:
http://www.pixel2life.com/tutorials/PHP_Co...d=1&ss=includes

As for SSI includes I have absolutely no idea about. Sorry happy.gif Perhaps those are somehwere around the tutorial database as well.
Tudi
Tnxy

Nothing about SSI includes, but I guess I'll have to start learning my php anywayz smile.gif

You've been of great help. tnx
raenef
Not a problem. happy.gif Glad I could help in some way.
Ruben K
This probably doesnt affect as <?xml does not equal <?
raenef
Perhaps, but <?xml was causing an error for me, causing my php scripts to not function. However when I turned short_open_tags off everything went smoothly.
HaloprO
Cliff, it does, the first sign of <? tells php that it want's to start a script
Jamie Huskisson
QUOTE(raenef @ May 11 2005, 04:31 AM) *
To fix:
Open your php.ini file and look for:
CODE
short_open_tag = On

and change it to:
CODE
short_open_tag = Off


Save and close it. Now in order to use php code; you must start with <?php... instead of the short tag <?...
However you should now be able to use PHP and XHTML together flawlessly.


This fixes it, if you've read the tutorial above smile.gif And I think raenef means PHP and XML as opposed to XHTML
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.