웹 응용 프로그램의 일부에는 iFrame에서 페이지를로드하거나 다운로드 할 수있는 약간의 Ajax 메서드가 있습니다.PHP UTF-8 ~ GB2312
Google은 검색 엔진에서 검색 결과를 저장하고 스크립트를 통해 Google 정보와 검색 HTML이 포함 된 파일을 엽니 다. 우리는 위에서 (우리의 정보) 꼭대기에서 필요하지 않은 것들을 제거한 다음, $ html 변수를 echo'ing하거나 임시 파일에 넣고 다운로드를 위해 dishing하여 제공합니다.
문제 : iFrame에서 페이지를로드하고 다른 모든 것이 있기 때문에 UTF-8로로드됩니다. 파일을 수동으로 다운로드하면 정상적으로 작동하며 FF는 엔딩이 x-gbk라고 알려줍니다.
mb_convert_encoding을 사용하지 않으려 고 시도했습니다. 우리는이 서버에서 PHP4를 사용하고 있습니다.
생각하십니까?
편집 : 코드이
f(!isset($_GET['file']) || $_GET['file'] == '')
{
header("location:index.php");
}
$download = false;
if(!isset($_GET['view']) || $_GET['view'] != 'true')
{
$download = true;
}
$file = LOG_PATH . $_GET['file'];
$fileName = end(explode("/", $file));
$fh = fopen($file, "rb");
if(!$fh)
{
echo "There was an error in processing this file. Please retry.";
return;
}
// Open HTML file, rip out garbage at top, inject "http://google.com" before all "images/"
$html = fread($fh, filesize($file));
fclose($fh);
// Need to trim off our headers
$htmlArr = explode("<!", $html, 2);
$htmlArr[1] = "<!" . $htmlArr[1];
if(strstr($file, "google"))
{
$html = str_replace('src="/images/', 'src="http://google.com/images/', $htmlArr[1]);
$html = str_replace('href="/', 'href="http://google.com/', $html);
}
else if(strstr($file, "/msn/"))
{
$html = str_replace('src="/images/', 'src="http://bing.com/images/', $htmlArr[1]);
$html = str_replace('href="/', 'href="http://www.bing.com/', $html);
}
else
{
$html = $htmlArr[1];
}
if(strstr($file, "baidu"))
{
$html = mb_convert_encoding($html, 'utf-8'); // Does not work
}
if($download)
{
// Write to temporary file
$fh = fopen("/tmp/" . $fileName, 'w+');
fwrite($fh, $html);
fclose($fh);
$fh = fopen("/tmp/" . $fileName, "rb");
header('Content-type: application/force-download;');
header("Content-Type: text/html;");
header('Content-Disposition: attachment; filename="' . $fileName . '"');
fpassthru($fh);
fclose($fh);
unlink("/tmp/" . $fileName);
}
else // AJAX Call
{
echo $html;
}
특히 iframe에 페이지를로드하는 방법에 대한 몇 가지 코드를 보여주십시오. –
추가됨. 감사!! – Thomas
[mb_list_encodings] (http://us2.php.net/manual/en/function.mb-list-encodings.php)의 결과는 무엇입니까? 편집 : 저주, 당신은 PHP4에있어, 그 기능은 PHP5 필요합니다 ... FWIW, 귀하의 소스 인코딩 * PHP5에 대한 해당 페이지에 나열되지 않습니다 *. mb_ * 함수가 인코딩과 관련하여 무엇을해야할지 모를 수도 있습니다. – Charles