Elliott
Elliott

Reputation: 3864

xml version 1.0 encoding utf-8 in php?

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\"?>";
?>

Upvotes: 1

Views: 16689

Answers (4)

cwallenpoole
cwallenpoole

Reputation: 82028

I'm inclined to agree w/ @just that this is likely to do with short_open_tag = On. Here are a few ways to fix this.

You could break the tag into pieces (short, sweet, and easy, but it has to be done for every instance):

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

You could modify the php.ini directly (permanent and holistic, the best solution in my opinion but it requires modifo get IIS ication of php.ini and restart of Apache).

Or, you could use htaccess to define the ini setting for you. This gets around of the issues most of the issues w/ 1 & 2, but it requires Apache (I have no idea how to get IIS to make this work)

Upvotes: 3

just somebody
just somebody

Reputation: 19247

the problem is short_open_tag = On in your php.ini

Upvotes: 3

leepowers
leepowers

Reputation: 38318

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

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

Upvotes: 1

Elle H
Elle H

Reputation: 12217

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"?>';

Upvotes: 0

Related Questions