http://www.amazon.co.jp/gp/product/4797348461/
SakuraのStandardで掲示板を制作中です
▼ソース
a.) in_enc.php:入力文字コードを内部文字コード(SJIS-win)に変換
b.) out_enc.php:内部文字コードを出力文字コード(SJIS-win)に変換
c.) bbs.php:掲示板本体
d.) bbs_d.txt:掲示板のデータ
▼解説
c から、a,b をrequire_once し、a,bに定義したfunction(input_encode, output_encode)をc のソースの上部(a)と下部(b)で実行
※各ソースは、eucで保存
※php.iniに、以下を記入
mbstring.language = Japanese
mbstring.internal_encoding = eucJP-win
mbstring.http_input = pass
mbstring.http_output = pass
mbstring.encoding_translation = Off
mbstring.detect_order = SJIS-win, eucJP-win, JIS, UTF-8, ASCII
ブラウザで見ると、euc(ソースの文字コード)のままで、
SJIS-winに変換されてません。
何卒、ご指導くださいませ!
php.iniに下記の設定を記入すればSJIS-winで表示されると思います。
output_buffering = On output_handler = mb_output_handler
> SJIS-winに変換されてません。
これは
> output_encode();
が、HTMLを出力した後に実行されているからでしょう。
出力エンコードを変更するのが mbstring.http_output なら、入力も mbstring.http_input ( mbstring.encoding_translation の変更も要)にお任せしては?
<?php
/**
*入力文字コードを内部文字コードに変換する
*/
function input_encode()
{
//入力文字コードを内部文字コードに変換する
if (isset($_GET)) {
mb_convert_variables(mb_internal_encoding(), 'SJIS-win', $_GET);
}
if (isset($_POST)) {
mb_convert_variables(mb_internal_encoding(), 'SJIS-win', $_POST);
}
}
?>
▼c.) bbs.php:掲示板本体
<?php
require_once 'input_encode.php';
require_once 'output_encode.php';
input_encode();
if (isset($_GET['comment'])) {
$comment = $_GET['comment'];
$comment = str_replace(array("\r", "\n"), "", $comment);
}
$filename = 'mobile_bbs_data.txt';
if (!file_exists($filename)) {
touch($filename);
}
$handle = fopen($filename, 'a+');
if (isset($comment)) {
fseek($handle, 0);
fwrite($handle, $comment . "\n");
}
$comment_list = array();
if (filesize($filename) > 0) {
fseek($handle, 0);
$data = fread($handle, filesize($filename));
$comment_list = explode("\n", $data);
$comment_list = array_reverse($comment_list);
}
fclose($handle);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset='Shift_JIS'" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<title>モバイル掲示板</title>
</head>
<body>
モバイル掲示板(Chap2)<br>
<form action="" method="GET">
<input type="text" name="comment" value="">
<input type="submit" value="書き込み">
</form>
<hr>
<?php
foreach ($comment_list as $comment_item) {
if (!empty($comment_item)) {
echo $comment_item . '<br><hr>';
}
}
?>
</body>
</html>
<?php output_encode(); ?>
の内容がわからないと答えようがないのですが・・・・
▼output_encode.php
<?php
function output_encode()
{
ini_set('mbstring.http_output', 'SJIS-win');
}
?>
↑Sakura Internet の特性なのか。フルパスで require_once してみましたが、まだだめです orz...