+ Reply to Thread
Results 1 to 3 of 3

Thread: <?xml> for XHTML Prevents PHP Code from Running

  1. #1
    shawntc is offline x10Hosting Member shawntc is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    62

    <?xml> for XHTML Prevents PHP Code from Running

    When it comes to standards, I like to comply. As such, when I make an XHTML document, I begin it with this:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    However, this creates a problem. Whenever I try to put PHP code using <?php ... ?> the site will give me an error about the PHP parser on line 1, where the <?xml> tag is. Short of removing that tag, are there any work-arounds?

    Thanks!
    For God so loved the world that he gave is one and only son, that whoever believes in him shall not perish but have eternal life. - John 3:16
    MY SITE!

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: <?xml> for XHTML Prevents PHP Code from Running

    That's the problem with short tags. Since you can't change PHP directives (unless you have a VPS and perhaps paid account, but I'm not certain of the latter), there are various other solutions. One is to echo some part of the XML directive. A simpler is:
    PHP Code:
    <<?php ?>?xml ...>
    which will work whether or not short tags are enabled. If you can rely on short tags being turned on (though this may come back to haunt you if you change hosts or the server config ever changes), you can use the even shorter:
    PHP Code:
    <<??>?xml ...>
    Last edited by misson; 06-01-2010 at 12:16 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    shawntc is offline x10Hosting Member shawntc is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    62

    Re: <?xml> for XHTML Prevents PHP Code from Running

    Quote Originally Posted by misson View Post
    That's the problem with short tags. Since you can't change PHP directives (unless you have a VPS and perhaps paid account, but I'm not certain of the latter), there are various other solutions. One is to echo some part of the XML directive. A simpler is:
    PHP Code:
    <<?php ?>?xml ...>
    which will work whether or not short tags are enabled. If you can rely on short tags being turned on (though this may come back to haunt you if you change hosts or the server config ever changes), you can use the even shorter:
    PHP Code:
    <<??>?xml ...>
    Sounds good. I don't plan on relying on short tags.
    For God so loved the world that he gave is one and only son, that whoever believes in him shall not perish but have eternal life. - John 3:16
    MY SITE!

+ Reply to Thread

Similar Threads

  1. Running ASP Code
    By randomize in forum Scripts & 3rd Party Apps
    Replies: 18
    Last Post: 12-31-2010, 05:29 PM
  2. PHP: Running code from string.
    By borntyping in forum Programming Help
    Replies: 8
    Last Post: 01-31-2010, 05:13 PM
  3. Xhtml
    By Ub3|2 5oIDaT in forum Programming Help
    Replies: 3
    Last Post: 03-08-2008, 03:12 PM
  4. XHTML help please
    By mac173 in forum Graphics & Webdesign
    Replies: 3
    Last Post: 01-29-2008, 11:39 AM
  5. xHTML and CSS
    By Bryon in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 08-14-2005, 11:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers