xml pages with <? in it are choking my PHP code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawrence

    xml pages with <? in it are choking my PHP code

    Most of our designers prefer to work in Dreamweaver. They now, this
    month, want to produce templates that are valid XHTML 1.0. In
    Dreamweaver, this is as simple as clicking a button.

    Up till now, we've been storing the templates in a database, bring
    them out when a webpage needs to be rendered, and hitting the page
    with eval(). The eval() function goes through and spits out the pure
    HTML and takes any PHP commands it finds and executes. All was well
    and good.

    Problems have arisen now that the designers want their code to be
    XHTML valid. This means having, at the top of the page, a declaration
    that looks like:

    <?xml // more stuff here.

    Of course this is giving parse errors. The PHP parser sees the "<?"
    and assumes what follows is PHP, but can find a command called xml.
    Not sure how to solve this one. Does anyone have some creative ideas?
    Some of the PHP commands embedded in the templates have echo and print
    statements, so there is no way to remove and then later replace the
    XML declaration.
  • SeeSchloss

    #2
    Re: xml pages with &lt;? in it are choking my PHP code

    > Of course this is giving parse errors. The PHP parser sees the[color=blue]
    > "<?" and assumes what follows is PHP, but can find a command
    > called xml. Not sure how to solve this one. Does anyone have some
    > creative ideas? Some of the PHP commands embedded in the
    > templates have echo and print statements, so there is no way to
    > remove and then later replace the XML declaration.[/color]

    You can fix this by editing php.ini to allow only <?php
    tags to trigger php : set short_open_tags to off.


    --
    SeeSchloß - http://gpu.sourceforge.net

    Comment

    • Martin Lucas-Smith

      #3
      Re: xml pages with &lt;? in it are choking my PHP code



      [color=blue]
      > Most of our designers prefer to work in Dreamweaver. They now, this
      > month, want to produce templates that are valid XHTML 1.0. In
      > Dreamweaver, this is as simple as clicking a button.[/color]

      Glad to hear your designers are taking such a worthwhile step.

      [color=blue]
      > Problems have arisen now that the designers want their code to be XHTML
      > valid. This means having, at the top of the page, a declaration that
      > looks like:
      >
      > <?xml // more stuff here.[/color]

      Bear in mind that the <?xml declaration isn't actually required for XHTML
      validity. Just using the DOCTYPE is sufficient.


      Martin Lucas-Smith www.geog.cam.ac.uk/~mvl22


      Comment

      • Justin Koivisto

        #4
        Re: xml pages with &lt;? in it are choking my PHP code

        lawrence wrote:[color=blue]
        > Some of the PHP commands embedded in the templates have echo and print
        > statements, so there is no way to remove and then later replace the
        > XML declaration.[/color]

        Sure there is, use the output buffering to capture everything first.

        ob_start();
        // all your stuff goes here

        Then when you want to display it all:
        $x=ob_get_conte nts();
        ob_end_clean();

        // echo out the <?xml tag and content
        echo '<?xml version="1.0" encoding="iso-8859-1"?>',"\n",$ x;

        --
        Justin Koivisto - spam@koivi.com
        PHP POSTERS: Please use comp.lang.php for PHP related questions,
        alt.php* groups are not recommended.

        Comment

        • Savut

          #5
          Re: xml pages with &lt;? in it are choking my PHP code

          Just

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

          do the job

          "lawrence" <lkrubner@geoci ties.com> a écrit dans le message de
          news:da7e68e8.0 309180948.54edf 7f9@posting.goo gle.com...[color=blue]
          > Most of our designers prefer to work in Dreamweaver. They now, this
          > month, want to produce templates that are valid XHTML 1.0. In
          > Dreamweaver, this is as simple as clicking a button.
          >
          > Up till now, we've been storing the templates in a database, bring
          > them out when a webpage needs to be rendered, and hitting the page
          > with eval(). The eval() function goes through and spits out the pure
          > HTML and takes any PHP commands it finds and executes. All was well
          > and good.
          >
          > Problems have arisen now that the designers want their code to be
          > XHTML valid. This means having, at the top of the page, a declaration
          > that looks like:
          >
          > <?xml // more stuff here.
          >
          > Of course this is giving parse errors. The PHP parser sees the "<?"
          > and assumes what follows is PHP, but can find a command called xml.
          > Not sure how to solve this one. Does anyone have some creative ideas?
          > Some of the PHP commands embedded in the templates have echo and print
          > statements, so there is no way to remove and then later replace the
          > XML declaration.[/color]


          Comment

          • Philippe Saladin

            #6
            Re: xml pages with &lt;? in it are choking my PHP code


            "lawrence" <lkrubner@geoci ties.com> a écrit dans le message news:
            da7e68e8.030918 0948.54edf7f9@p osting.google.c om...[color=blue]
            > Of course this is giving parse errors. The PHP parser sees the "<?"
            > and assumes what follows is PHP,[/color]

            if short_open_tag is off in php.ini, only <?php is allowed to begin a php
            script. It should resolve the problem.
            Regards,
            Philippe


            Comment

            • lawrence

              #7
              Re: xml pages with &lt;? in it are choking my PHP code

              Thanks for all the intelligent responses. The echo statment seems
              simplest but it seems inflexible - I'd have to change the code every
              time a designer wanted a different doctype declaration. I might make a
              function call for the doctype and provide some forms for the
              designers, but neither they nor I would like the extra work. So
              adjusting the ini file sounds best.

              Comment

              Working...