views:

185

answers:

3

Hi, I am trying to show

xml version 1.0 encoding utf-8 in php, I have tried :

echo '<?xml version="1.0" encoding="utf-8"?>';

but this doesnt validate on w3c, when using it in xhtml, the php shows an error.

Whats the easiest way to fix this? With it validating

Thanks

error on w3c:

Line 5, Column 46: character "'" not allowed in prolog

echo '<?xml version="1.0" encoding="utf-8"?>';

Line 5, Column 45: XML Parsing Error: Start tag expected, '<' not found

echo '<?xml version="1.0" encoding="utf-8"?>';

php error:

Parse error: syntax error, unexpected T_STRING in /home/public_html//request.php on line 7

<?php 
session_start();
include ('../connection.php');
include ('../functions.php');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
?>
A: 

Based on your error messages, sorry if this comes off condescending, but is your code wrapped in PHP opening and closing tags?

That is, does your file look like this?

<?php
echo '<?xml version="1.0" encoding="utf-8"?>';
?>

Or just this?

echo '<?xml version="1.0" encoding="utf-8"?>';
Zurahn
Yes its wrapped, most of it is xhtml I just start/end php tags where I need to include php.
Elliott
A: 

Did you include the <?php tag at the start of your script?

<?php
echo '<?xml version="1.0" encoding="utf-8"?>';
?>
pygorex1
yup it does work by echo'ing just that it doesnt pass and it *needs* to :p
Elliott
Is there *definitely no mention* of <?php in the validated source code any more?
Pekka
What does the first line of your script look like? If the first line is an XML declaration AND `short_open_tags` are on then you'll get a parse error.
pygorex1
added the first 3lines
Elliott
my guess would be that one of the included files is missing a closing `?>` tag for an opening `<?php`. The error is somewhere in code not shown, as the code example in the question is fine.
pygorex1
There are no problems in the scripts....its w3c validator finding the error when I echo the xml version/
Elliott
A: 

the problem is short_open_tag = On in your php.ini

just somebody
is it possible to turn these off without accessing the php.ini?
Elliott
i believe short_open_tag is non-changeable via ini_set() you would have to access the php.ini directly
Anthony Forloney