Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts

    Question How can I add <?xml tag in php file

    Hi friends,

    Is it posssible to add
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    tag, before DOCTYPE as given in the w3 website, if I'm using a .php file ?

    Please let me know..

    thanks n regards,
    art
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Yes but short open tags needs to be set to off. Personally though I wouldn't bother with that line as it will mess up the display of IE6. Its not required either. I'm going to go out on a limb here and guess that you probably have no idea what xml is or what that line is for.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Yes but short open tags needs to be set to off. Personally though I wouldn't bother with that line as it will mess up the display of IE6. Its not required either. I'm going to go out on a limb here and guess that you probably have no idea what xml is or what that line is for.
    Thanks for the reply
    (even though I couldn't get the idea completely )

    I was just reading this one http://www.w3.org/TR/xhtml1/#strict

    and the 5th item under this says
    ...however XHTML document authors are strongly encouraged to use XML declarations in all their documents...
    It may not be for me atleast for now
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    Regular Coder croatiankid's Avatar
    Join Date
    Jan 2006
    Posts
    665
    Thanks
    1
    Thanked 12 Times in 12 Posts
    It also says
    Such a declaration is required when the character encoding of the document is other than the default UTF-8 or UTF-16 and no encoding was determined by a higher-level protocol.
    You should IMO always use UTF-8 character encoding. Read just a little bit about it and you'll see why.

    Aerospace is right in that adding that before your doctype will put IE into quirks mode (non-standards mode), as will anything (that shows up in the source code) before the doctype.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    With shorttags on you can always write it as:

    <? echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'; ?>
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Quote Originally Posted by felgall View Post
    With shorttags on you can always write it as:

    <? echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'; ?>
    Thank you so much,

    This is exactly what I want.
    But I couldn't see much description about this 'shorttag' from the web.

    Could you please explain a little more ?

    regards,
    art.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Quote Originally Posted by felgall View Post
    With shorttags on you can always write it as:

    <? echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'; ?>
    Thank you so much,

    This is exactly what I wanted.
    But I couldn't see much description about 'what is shorttag' from the web.

    Could you please explain a little more ?

    regards,
    art.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    http://us.php.net/ini.core
    Learn to read the manual.
    Quote Originally Posted by php.net
    short_open_tag boolean

    Tells whether the short form (<? ?>) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"'; ?>. Also if disabled, you must use the long form of the PHP open tag (<?php ?>).

    Note: This directive also affects the shorthand <?=, which is identical to <? echo. Use of this shortcut requires short_open_tag to be on.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #9
    Regular Coder
    Join Date
    Nov 2005
    Location
    North Canton, Ohio
    Posts
    118
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by felgall View Post
    With shorttags on you can always write it as:

    <? echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'; ?>
    couldn't he just do this?
    Code:
    <?php
    //code...
    echo '<?xml version="1.0" encoding="utf-8" ?>\n';
    //more code...
    ?>
    As long as your code is encased as a literal, it shouldn't run it like it was part of the script. Also, it's always a good idea to use <?php, instead of just using <?.

    In fact, I don't see a problem if you even used this:
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <?php
    //code...
    ?>
    It's always worked for me, but I use PHP 5.2, and I'm not certain if it'll work on older versions.

    Of course, I always use ISO, and if the browser dosn't support ISO, I have it replace with UTF-8, so I always suggest doing something like this.

    Code:
    <?php
        echo "<?xml version=\"1.0\" encoding=\"";
        if (stristr($_SERVER["HTTP_ACCEPT_CHARSET"], "iso-8859-1"))
        {
            echo "iso-8859-1";
        }
        else
        {
            echo "utf-8";
        }
        echo "\" ?>\n";
        //more code...
    ?>
    But that's only if you like ISO.
    Last edited by Blaher; 06-10-2007 at 01:53 PM. Reason: adding quote

  • #10
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Thanks for the comments.


    Quote Originally Posted by Blaher View Post
    couldn't he just do this?
    [code]
    <?php
    //code...
    echo '<?xml version="1.0" encoding="utf-8" ?>\n';
    //more code...
    ?>
    The difference b/w
    Code:
    echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>';
    and
    Code:
    echo '<?xml version="1.0" encoding="utf-8" ?>';
    is its very easy to add a comment (//) in the first one where as not in the second one ,apart from that everything same.

    Now, shall I ask one more question..

    I've just gone through http://www.w3schools.com/xhtml/default.asp

    and couldn't see an <?xml tag before any example document( or even in this sites source)

    But http://www.w3.org/TR/xhtml1/#strict
    mention about <?xml tag and this website's source has used it.

    Are they using any special properties of xml for the building of this site?
    Or What is the purpose of this tag here?
    (Please give some helpful totorial links on this issue)

    Thanks n regards,
    art
    Last edited by abduraooft; 06-12-2007 at 04:02 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #11
    Regular Coder
    Join Date
    Nov 2005
    Location
    North Canton, Ohio
    Posts
    118
    Thanks
    11
    Thanked 4 Times in 4 Posts
    The reason why it's useful to use the <?xml?> tag is for a few reasons.
    When you validate any +xml document, on some validations they will recommend you have it.
    You don't really need it in a lot of cases though, unless your using something other than xhtml in your source. The only reason I have it is to declare it's a xml document, and I like to throw my own tags sometimes before and after the document and use xsl to translate it. There may be other reasons why to declare it as a xml document, but none that I really use myself.

    Also, if you have different browsing support, you could have both your xhtml, wml, rss, and maybe even your vxml on the same page and your browser (depending if it's web, rss viewer, a cellphone, or your phone calling a voxio server) should handle it.

    I also seen something about Xlink and Xpath, but I never stopped yet and learned them or what they are.
    Last edited by Blaher; 06-13-2007 at 05:06 AM.

  • #12
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Wow.. nice explanation . Thanks.

    Now I'm curious to know one more thing.

    Is it possible to create an appealing website with xml+xslt only?
    Any such pretty websites exist?
    (I'm very new to xml and someone told me to concentrate more on xml rather than html)

    regards,
    art
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #13
    Regular Coder
    Join Date
    Nov 2005
    Location
    North Canton, Ohio
    Posts
    118
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by abduraooft View Post
    Wow.. nice explanation . Thanks.

    Now I'm curious to know one more thing.

    Is it possible to create an appealing website with xml+xslt only?
    Any such pretty websites exist?
    (I'm very new to xml and someone told me to concentrate more on xml rather than html)

    regards,
    art
    Yes, it is possible to do that. But you still have to use the html to translate it.
    Here might be a example for you to use.
    http://blahertech.dnsalias.net/_dev/sitemap.php
    using the xsl file of
    http://blahertech.dnsalias.net/_dev/templates/xsl.php

    Although mine right now is a little buggy and I'm still working on it.
    But overall, http://www.w3schools.com/xsl/ is a good place to learn how to use it.


  •  

    Posting Permissions

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