在php中编码utf-8的xml版本?

时间:2022-10-24 22:53:20

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

在php中编码utf-8的xml版本1.0,我尝试过:

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

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

但是这并没有在w3c上验证,当在xhtml中使用它时,php显示了一个错误。

Whats the easiest way to fix this? With it validating

解决这个问题最简单的方法是什么?用它验证

Thanks

谢谢

error on w3c:

在w3c错误:

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

第5行,第46列:prolog中不允许使用“'”字符

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

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

第5行,第45列:XML解析错误:开始标记预期,'<'未找到。

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

php error:

php错误:

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

语法错误,/home/public_html//request中的意外T_STRING。php在第7行

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

4 个解决方案

#1


3  

the problem is short_open_tag = On in your php.ini

问题是php.ini中的short_open_tag = On

#2


3  

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.

我倾向于同意w/ @,只是这可能与short_open_tag = On有关。这里有一些方法来解决这个问题。

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

可以修改php。ini直接(永久和整体的,我认为最好的解决方案,但是它需要修改php的IIS)。ini和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)

或者,您可以使用htaccess为您定义ini设置。这解决了大多数问题w/ 1和2,但是它需要Apache(我不知道如何让IIS工作)

#3


1  

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

你包括 <吗?在脚本开始时的php标记?< p>

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

#4


0  

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

根据您的错误消息,如果这是屈尊的,对不起,但是您的代码是用PHP打开和关闭标记包装的吗?

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

#1


3  

the problem is short_open_tag = On in your php.ini

问题是php.ini中的short_open_tag = On

#2


3  

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.

我倾向于同意w/ @,只是这可能与short_open_tag = On有关。这里有一些方法来解决这个问题。

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

可以修改php。ini直接(永久和整体的,我认为最好的解决方案,但是它需要修改php的IIS)。ini和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)

或者,您可以使用htaccess为您定义ini设置。这解决了大多数问题w/ 1和2,但是它需要Apache(我不知道如何让IIS工作)

#3


1  

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

你包括 <吗?在脚本开始时的php标记?< p>

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

#4


0  

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

根据您的错误消息,如果这是屈尊的,对不起,但是您的代码是用PHP打开和关闭标记包装的吗?

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