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

  php

Q(Question):

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.

A(Answer):

> 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.

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

A(Answer):

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.

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

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.

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
www.lucas-smith.co.uk

A(Answer):

lawrence wrote:

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.

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_contents();
ob_end_clean();

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


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

A(Answer):

Just

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

do the job

"lawrence" <lk******@geocities.com> a écrit dans le message de
news:da**************************@posting.google.c om…

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.

A(Answer):

"lawrence" <lk******@geocities.com> a écrit dans le message news:
da**************************@posting.google.com

Of course this is giving parse errors. The PHP parser sees the "<?"
and assumes what follows is PHP,

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

A(Answer):

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.

LEAVE A COMMENT