###前提・実現したいこと
会社の研修で、初めて PHP MYSQL のアプリを作成していmす。日本語(文字コード UTF-8)の取り扱いで苦慮しております。
ソースは以下です。一部 * にしてあります。
<?php $appid = '***GY-'; function escapestring($str) { return htmlspecialchars($str, ENT_QUOTES); } if(isset($_REQUEST['sentence'])){ $sentence = mb_convert_encoding($_REQUEST['sentence'], 'utf-8', 'auto'); }else{ $sentence = ""; } function show_keyphrase($appid, $sentence){ $output = "php"; $request = "http://jlp.yahooapis.jp/KeyphraseService/V1/extract?"; $request .= "appid=".$appid."&sentence=".urlencode($sentence)."&output=".$output; $proxy = array( "http" => array( "proxy" => "tcp://ta.jp:8080", 'request_fulluri' => true, ), ); $proxy_context = stream_context_create($proxy); $responsephp = file_get_contents($request, false, $proxy_context); $responsephp_rev = unserialize($responsephp); print_r($responsephp_rev); $where = "WHERE qt LIKE \"%"; echo "<br>"; foreach($responsephp_rev as $key => $value){ //echo $value; //echo "<br>"; //echo $key; $where .= $key . "%\" OR qt LIKE \"%"; } $where .= "zzwick%\""; //echo "<br>"; //echo $where; $con = mysql_connect("localhost", "root", "pass"); if ( $con == $FALSE ) { die("DB接続に失敗しました。"); } mysqli_select_db("mydb"); $sql = "select qt from faqs " . $where; $result = mysqli_query($sql,$con); if ( $result == $FALSE ) { die("検索結果が0件でした。"); } $num = mysqli_num_rows($result); echo $num; for ($i=0; $i<$num; $i++) { $r = mysqli_fetch_row($result); for ($j=0; $j<count($r); $j++) { echo "$r[$j] "; } echo "<br>"; } } ?> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>K****</title> </head> <body > <style> </style> <h2 class="title">K****</h2> <form method="POST" name="qform"> <textarea id="sentence" name="sentence" rows="4" cols="70"><?php echo escapestring($sentence) ?></textarea> <br> <input type="submit" name="command_query" value="抽出"> </form> <?php if($sentence){ show_keyphrase($appid, $sentence); } ?> </body> </html>###発生している問題・エラーメッセージ
1byte文字ではMySQL検索は正常に動くが、2byte(漢字)で検索をかけると結果がゼロになる(ヒットするはずがヒットしない)SELECT異常
結果表示も2byte系データは ?????????????????????????????????????????????????? に化ける
エラーメッセージ とくになし ###試したこと 試したこと mysqli_real_escape_string($con,$where); mb_convert_encoding($key, 'utf-8', 'auto'); ###補足情報(言語/FW/ツール等のバージョンなど) DB は UTF-8 で作成。テーブルも。データ作成でコピペしたが、コピー元のテキストファイルもUTF-8のはず 環境 Windows10 Hyper-V 仮想環境 Ubuntu 14.04 LTS PHP5 MySQL ?
回答1件
あなたの回答
tips
プレビュー