Php-fwrite坏字符

Php-fwrite坏字符,php,special-characters,file-get-contents,fwrite,Php,Special Characters,File Get Contents,Fwrite,我对文件内容和写入有问题 为了让脚本正常工作,我必须将外部URL中的内容打印到html文件中 我正在使用以下代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> &

我对文件内容和写入有问题

为了让脚本正常工作,我必须将外部URL中的内容打印到html文件中

我正在使用以下代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>

<?php
$url = 'http://www.vasttrafik.se/nasta-tur-fullskarm/?externalid=9021014005135000';
$content = file_get_contents($url);  
echo $content; // Actually writes out correct

$myFile = "response.php";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $content); // Doesn't write out correct ???
fclose($fh);
?>

</body>
</html>
$content = "\xEF\xBB\xBF";
$content .= utf8_encode(file_get_contents($url));  
解决了

我需要广告BOM(字节顺序标记)和utf8_编码

像这样:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>

<?php
$url = 'http://www.vasttrafik.se/nasta-tur-fullskarm/?externalid=9021014005135000';
$content = file_get_contents($url);  
echo $content; // Actually writes out correct

$myFile = "response.php";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $content); // Doesn't write out correct ???
fclose($fh);
?>

</body>
</html>
$content = "\xEF\xBB\xBF";
$content .= utf8_encode(file_get_contents($url));  

你到底是如何检查该文件中的结果的?@Dugi:没有帮助:/deceze:当我回显$content时,它工作正常。但当我浏览“response.php”时,字母“åäö”是wierd。。是的,当我运行这个脚本时,response.php文件被更新了。您所做的是使输出与您用来读取文件的任何内容兼容——文件中的数据从未被错误写入。