10/06/19 19:33:03 PoSyZtDI
<?php
header('Content-Type: text/html; charset=UTF-8');
mb_http_output("UTF-8");
ob_start("mb_output_handler");
?>
<form method="POST" action="">
<textarea name="replace" cols=20 rows=4></textarea>
<input type="submit" value="replace!!">
</form>
<?
if(isset($_POST["replace"])){
$before = $_POST["replace"];
echo $before;
echo mb_detect_encoding($before);
$after = str_replace("です", "でした", $before);
echo $after;
echo mb_detect_encoding($str)."<br>";
}
フォームで文字列置換をやりたいんだけど、うまくいきません。
置換前の文字列とその文字コード、置換後の文字列とその文字コードを表示させてますが、
「あいうえおです」みたいな日本語を入力しても、該当箇所が置換されないどころか文字列自体が表示されません。
しかも文字コードはどちらもSJISになっちゃいます。
どうしたらうまく置換できるのでしょうか。