Home > Backend Development > PHP Tutorial > php生成xml文件格式有关问题

php生成xml文件格式有关问题

WBOY
Release: 2016-06-13 13:35:22
Original
970 people have browsed it

php生成xml文件格式问题
请教大牛们 php能让生成的xml文件格式定死为unix utf-8格式吗
为什么我每次生成的都是 pc ANSI格式的
上代码:请大牛们帮我看下 怎么改就能让生成的文件格式是unix utf-8格式的,谢谢大哥大姐帮忙了:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php header("content-type:text/html;charset=utf-8");
$str = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<node>巴拉巴拉巴拉</node>
EOF;
//if(file_put_contents("F:/over.xml",$str)) {
//    echo "yesyesyes";
//} else {
//    echo "nononon";
//}

$dh = fopen("f:/over.xml","w");
$dh2 = fwrite($dh,$str);
fclose($dh);
?>


Copy after login


生成的文件 用editplus打开是pc ANSI格式的 我要生成的格式是unix utf-8的 祝好人有好报


------解决方案--------------------
那你的这个php程序文件要保存为unix utf-8格式
------解决方案--------------------
你的程序文件是 utf-8 的
只要写的时候 $dh2 = fwrite($dh, "\xef\xbb\xbf" . $str); 就可以了

如果是 gbk 的,需要转码
$str = iconv('gbk', 'utf-8', $str);

若要完全符合 unix 格式,还需要去掉‘回车’符
$str = preg_replach("/[\r\n]+/s", "\n", $str);
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template