Jump to content


Photo
- - - - -

Using PHP with XHTML


  • Please log in to reply
8 replies to this topic

#1 raenef

raenef

    Code Enforcer

  • Members
  • PipPipPip
  • 540 posts
  • Location:Battle Creek, Michigan
  • Interests:Web Development and Graphic Design

Posted 10 May 2005 - 11:31 PM

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.
<?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:
short_open_tag = On
and change it to:
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.

#2 Tudi

Tudi

    Young Padawan

  • Members
  • Pip
  • 42 posts

Posted 11 May 2005 - 09:44 AM

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.

#3 raenef

raenef

    Code Enforcer

  • Members
  • PipPipPip
  • 540 posts
  • Location:Battle Creek, Michigan
  • Interests:Web Development and Graphic Design

Posted 11 May 2005 - 11:11 AM

You're welcome. :) 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.pixel2lif...d=1&ss=includes

As for SSI includes I have absolutely no idea about. Sorry :hi: Perhaps those are somehwere around the tutorial database as well.

#4 Tudi

Tudi

    Young Padawan

  • Members
  • Pip
  • 42 posts

Posted 11 May 2005 - 05:11 PM

Tnxy

Nothing about SSI includes, but I guess I'll have to start learning my php anywayz ;)

You've been of great help. tnx

#5 raenef

raenef

    Code Enforcer

  • Members
  • PipPipPip
  • 540 posts
  • Location:Battle Creek, Michigan
  • Interests:Web Development and Graphic Design

Posted 11 May 2005 - 07:24 PM

Not a problem. ^_^ Glad I could help in some way.

#6 Ruben K

Ruben K

    Cliff

  • Twodded Staff
  • PipPip
  • 438 posts

Posted 12 May 2005 - 09:12 AM

This probably doesnt affect as <?xml does not equal <?

#7 raenef

raenef

    Code Enforcer

  • Members
  • PipPipPip
  • 540 posts
  • Location:Battle Creek, Michigan
  • Interests:Web Development and Graphic Design

Posted 12 May 2005 - 03:14 PM

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.

#8 HaloprO

HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 18 November 2005 - 06:04 PM

Cliff, it does, the first sign of <? tells php that it want's to start a script

#9 Jamie Huskisson

Jamie Huskisson

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 3,648 posts
  • Gender:Male
  • Location:Nottingham, UK

Posted 18 November 2005 - 06:26 PM

To fix:
Open your php.ini file and look for:

short_open_tag = On
and change it to:
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 <3 And I think raenef means PHP and XML as opposed to XHTML




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users