Results 1 to 16 of 16
  1. #1
    Join Date
    Jan 2002
    Posts
    428

    XHTML strict and PHP

    Assume I have had someone give me a static layout of a XHTML strict (not transitional) page. I want to merge my existing PHP page into that new page. Other than eliminating the deprecated elements like <center></center>, how would I integrate it? Do I just lump all the PHP code into the new document and put it between <?php and ?>?

  2. #2
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    You use PHP with XHTML in exactly the same way as you used PHP with HTML.

    PHP is a server side language and thus completely independent from the client side languages.

  3. #3
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    One thing though -- if you choose to include the xml declaration with your XHTML page, make sure you echo it with PHP, otherwise (if you have short_tags turned on) the PHP parser will complain about it.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  4. #4
    Join Date
    Jan 2002
    Posts
    428
    I can't even get

    <?php
    echo "Hello!";
    ?>

    to work, hmm?

  5. #5
    Join Date
    Aug 2003
    Location
    PA
    Posts
    110
    Well, you can login and see if the server is reading PHP. Then, make up a page where the only thing it should say is hello in the php file. See if the server is viewing php, then if it is parsing php code.

    If both are true, look at the html file itself when viewed in your browser. I have had instance where, by using some positioning tags, the debugging messages I was using were not easily seen..maybe this is what is going on.

    Other possibilities that I am assuming you have done...

    Save the page as a .php or .php4, or whatever extension you have you server set to view php files.

    Making sure that your php tagging is accurate, no wrong special characters.

    Please post back and let us know if you got it workin or not

    Later

  6. #6
    Join Date
    Jan 2002
    Posts
    428
    Maybe my underestanding of XHTML is all wrong. My site is completely PHP accessing a MySQL database. All pages are *.php. I was given a new layout for the site that I really like that is XHTML strict, but the person who made it did not include the PHP stuff. I was assuming that I could add in all the MySQL queries into the *.html file I was given using <?php and ?>. Is my understnading wrong?

  7. #7
    Join Date
    Aug 2002
    Location
    California
    Posts
    109
    Originally posted by pcgamez
    Is my understnading wrong?
    Yes, if you are saving the file as .html; at least that's what I gathered from your previous post.

    When you are using PHP functionality (i.e. MySQL queries) in your page, you have to save the page as .php.

    To make your PHP pages XHTML compliant, you'd use XHTML format for whatever HTML-code you embed in the <?php-tag?>. I could be wrong though...

    example:
    PHP Code:
    <?php
      
    // stuff
      
    echo "This is a test<br />"// as opposed to <br>
    ?>

  8. #8
    Join Date
    Jan 2002
    Posts
    428
    ah, that explains it then.

    *sigh* more work

  9. #9
    Join Date
    Jan 2002
    Posts
    428
    wait, now would I still leave the DOCTYPE declaration as the first line, and have the second line be <?php

    ?

  10. #10
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    4,695
    You can just:

    PHP Code:
    <?php
        
    echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\">\n";
        
    #rest of code ...
    ?>

  11. #11
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    You may find it useful to use XHTML 1.0 Transitional until you get used to it.

  12. #12
    Join Date
    Aug 2003
    Location
    PA
    Posts
    110
    Yes, get familiar with the presentation coding you are using, and then start implementing your server-side code.

    As for that, indeed, you will simply write your query, and then jsut place the strings in the areas of the 'templated' html file, but, you msut save it as a .php, o .php3, or .php4(.php is now the standard).

    Good that you found out what was wrong and learned from it!

    Take care

  13. #13
    Join Date
    Feb 2004
    Posts
    772
    Hi,

    You can embed your xhtml tags in different ways. Please try the ways given below.

    --------------------------------------------------------------------------------------
    &lt;
    echo('&lt;?xml version="1.0" encoding="utf-8"?&gt;');
    ?&gt;
    --------------------------------------------------------------------------------------

    --------------------------------------------------------------------------------------
    <?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
    --------------------------------------------------------------------------------------

    Or turn off PHP short tags. So <?php foo(bar); ?> is required, and <?xml ... > won't get parsed.

    Have a look at www.w3.org and http://validator.w3.org - it validates your work, and checks for errors on your page.

    Regards,

    Bright

  14. #14
    Join Date
    Mar 2004
    Location
    Granville OH
    Posts
    108
    Umm... you do not have to rename all of the files to .php. Just put
    Code:
    AddHandler php-script .html
    into either your .htaccess file in that directory or into the root configuration file.

  15. #15
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    Yes but if you have any plain HTML pages that don't contain PHP code you are wasting server resources by doing that.

  16. #16
    Join Date
    Mar 2004
    Location
    Granville OH
    Posts
    108
    yeah, but most servers are under utilized anyway. And the resources it takes to parse for php are minimal to the resources it takes to run php. Not saying that there aren't circumstances where this would be a bad idea. I just don't think this is one of them.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •