1

以下脚本并不总是能正确捕捉和转换外来字符。有人可以告诉我我缺少什么以使其更强大吗?

<?php
include("../index_head.inc.php");
$content = implode("",(@file("current.txt")));

$url = "http://XXXXXX.html?no_body=1";
$content = file_get_contents($url,'r');

if (isset($_GET['showcurrent']) && $_GET['showcurrent'] == '')
    {
    $content = substr($content,1,strpos($content,"<hr ")-1);
    }
    else 
    {
    $content = str_replace("<br style=\"clear:both\" />\n</p>", "</p>",$content);   
    $content = str_replace("ck1\"><img", "ck1\" target=_blank><img",$content);  
    };

$content = str_replace("<h3>current</h3>", "",$content);

echo "<div id=\"service\" style=\"width: 660px;padding-left:5px\">",str_replace("current.html","current.html",$content),"</div>";

include("../index_footer.inc.php");
?>

新信息:Pekka,你给了我在没有 str_replace() 的情况下检查页面如何发出的想法:

<?php
include("../index_head.inc.php");
$content = implode("",(@file("current.txt")));
$url = "XXXXXX.html?no_body=1";
$content = file_get_contents($url,'r');
echo "<div id=\"service\" style=\"width: 660px;padding-left:5px\">",$content,"</div>";

似乎问题出在其他地方,因为即使使用 str_replace(),我也会得到相同的修饰!如果您能帮我解决这个问题,我将不胜感激。我看过你的愿望清单。;)

4

2 回答 2

3

您是否在 php 中包含字符集?

尝试这个:

header('Content-Type: text/html; charset=utf-8');

如果不起作用,请在 str 替换之前检查您的文件是否已保存在 utf8 中:

utf8_encode ( string $data );

在相反的情况下使用:

utf8_decode( string $data );

希望能帮助到你!

于 2013-10-14T07:03:32.157 回答
0

谢谢 SBO - 它确实有帮助!我只是将代码更改为:

<?php
include("../index_head.inc.php");
$content = implode("",(@file("current.txt")));

$url = "http://XXXXXX.html?no_body=1";
$content = file_get_contents(utf8_encode($url),'r');

if (isset($_GET['showcurrent']) && $_GET['showcurrent'] == '')
    {
    $content = substr($content,1,strpos($content,"<hr ")-1);
    }
else 
{
$content = str_replace("<br style=\"clear:both\" />\n</p>", "</p>",$content);   
$content = str_replace("ck1\"><img", "ck1\" target=_blank><img",$content);  
};

$content = str_replace("<h3>current</h3>", "",$content);

echo "<div id=\"service\" style=\"width: 660px;padding-left:5px\">",str_replace("current.html","current.html",utf8_decode($content)),"</div>";

include("../index_footer.inc.php");
?>

一切正常。非常感谢您的帮助。

于 2013-10-14T17:52:13.283 回答