携帯サイト文字化け

このQ&Aのポイント
  • 現在、既存システムの携帯サイトを作っているのですが、auでの文字化けが解決できずに困っています。
  • 自分で解決するにはかなり限界がきています。
  • 文字化け対策についてアドバイスを頂けないでしょうか?
回答を見る
  • ベストアンサー

携帯サイト文字化け

いつもお世話になっております。 現在、既存システムの携帯サイトを作っているのですが、 auでの文字化けが解決できずに困っています。 1週間程悩んでいるのですが、 自分で解決するにはかなり限界がきています。 そこで、ここのサイトで質問させて頂くことにしました。 詳細内容 ・開発言語:PHP ・データベース:MySQL ・文字コード:EUC-JP(既存システムが全てEUC-JPで作成されているので、携帯サイトもEUC-JPで作成しています。) ・システム概要:既存システム(物件検索システム)の携帯対応 データベースに保存されているデータを取得して、表示させる。 ・バグ内容:auでの文字化け *ただ、au携帯でも文字化けが起こる機種と起こらない機種が存在します。 例えば、W61SAだと起こりませんが、W44TやW53CAだと文字化けが発生します。 ヘッダー部分の書き方に問題があると思うのですが、 文字化け対策についてアドバイスを頂けないでしょうか? <?php //キャリア判定_start function GetCarryer($agent){ if (preg_match("/^DoCoMo\/2\.0/i", $agent)) { // DoCoMo FOMA (XHTML) $type="DOCOMO"; } else if (preg_match("/^DoCoMo\/1\.0/i", $agent)) { // DoCoMo MOVA $type="DOCOMO"; } else if (preg_match("/^SoftBank/i", $agent)) { // SoftBank $type="SOFTBANK"; } else if (preg_match("/^(Vodafone|MOT-)/i", $agent)) { // Vodafone 3G $type="SOFTBANK"; } else if (preg_match("/^J\-PHONE/i", $agent)) { // Vodafone 1G,2G } else if (preg_match("/^KDDI\-/i", $agent)) { $type="AU"; // au (XHTML) } else if (preg_match("/UP\.Browser/i", $agent)) { // au (HDML) TU-KA $type="AU"; } else if (preg_match("/WILLCOM/i", $agent) || preg_match("/DDIPOCKET/i", $agent)) { // WILLCOM Air EDGE $type="SOFTBANK"; } else if (preg_match("/^PDXGW/i", $agent)) { // WILLCOM EDGE LINK $type="SOFTBANK"; } else if (preg_match("/^(L\-mode)/i", $agent)) { // L-mode $type="NG"; } else { //PC or フルブラウザ $type="PC"; } return $type; } $agent = $_SERVER['HTTP_USER_AGENT']; if(GetCarryer($agent)=="PC"){ print<<<ERROR <div style="margin:20px auto 0px auto;text-align:center;color:#4E4E4E;font-size:14px;">このサイトはパソコンからは見ることが出来ません。</div> ERROR; exit; } //キャリア判定_end //DocomoのCSS対策 header('Content-Type: application/xhtml+xml; charset=EUC-JP'); print <<<DATA <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"> DATA; ?> <head> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=EUC-JP" /> <meta http-equiv="Content-Type" content="text/css" /> <meta http-equiv="Pragma" content="no-cache" /> <meta http-equiv="Cache-Control" content="no-cache" /> <meta http-equiv="Expires" content="-1" /> <meta name="description" content="" /> <meta name="keywords" content="テスト投稿1件目" /> <title>モバイル版テストページ</title> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <a name="top"></a> <div style="background-color:#333399"><div style="font-size:xx-small; color:#FFFFFF; text-align:center">モバイル版テスト用会社</div></div> <div><img src="../../../img/spacer.gif" height="5"></div> <div style="font-size:xx-small;"> <div style="color:#000099;">テスト投稿</div> <hr size="1" style="margin-top:2px;margin-bottom:2px;" /> <div><img src="../../../img/spacer.gif" height="3"></div> <div style="font-size:xx-small;"> テスト投稿07<br /> <?php /** 処理省略(データベースからデータの取得と出力処理) **/ ?> <a href="#">>>詳細へ</a> <br /> </div> <hr size="1" style="margin-top:2px;margin-bottom:2px;" /> <a href="#" accesskey="0">トップページへ</a> </div> </body> </html>

  • PHP
  • 回答数1
  • ありがとう数1

質問者が選んだベストアンサー

  • ベストアンサー
  • memphis
  • ベストアンサー率40% (975/2395)
回答No.1

携帯電話はShift-JIS以外の文字コードへ未対応の機種が多いから EUCから変換して表示したほうがいいですよ。

adachi0000
質問者

お礼

ご回答ありがとうございます。 そうですね、 一度Shift-JISに変換してから表示させてみます。 文字コードについても現在勉強中で、 コードの変換方法などを調べて修正してみます。

関連するQ&A

  • 携帯とPCの振り分け

    同じドメインにて携帯とPCの振り分けなのですが、htaccessにて振り分けたのですが、ブラウザに「振り分けがループしています」とでるのですが、 これはなぜでしょう? htaccessの中身の内容ですが、 DirectoryIndex index.php index.html index.htm これで読み込んだindex.phpの中身は <?php $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/^DoCoMo/i", $agent)){ header("Location: http://www.○○○○○.com/mobile/index.xhtml"); exit; }else if(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]|SoftBank)/i", $agent)){ header("Location: http://www.○○○○○.com/mobile/index.xhtml"); exit; }else if(preg_match("/^KDDI\-/i", $agent) || preg_match("/UP\.Browser/i", $agent)){ header("Location: http://www.○○○○○.com/mobile/index.xhtml"); exit; }else{ header("Location: http://www.○○○○○.com/"); exit; } ?> サーバはlolipopでhtaccessのパーミッションは604で phpのパーミッションは700です。

    • 締切済み
    • CGI
  • xhtmlで携帯サイトを作成するとsoftbankで文字化け

    こんばんは。 夜分遅くに質問させていただきます。 最近、xhtmlで携帯サイトを作成しているのですが どうも、softbankから閲覧すると文字がすべて?????????????となって 表示されるようなのです。 これはxhtmlの表記が間違っているために起こっている問題なのでしょうか? それとも、文字コードの問題なのでしょうか?(shift-jis)で固定しています。 また、phpで作成しているため、そのような問題が起きたのか、とも思います。 以下に上部のソースを記述いたしますので、どなたか、何処に問題があるのか教えていただけないでしょうか? よろしくお願いします。 <? echo"<?xml version=\"1.0\" encoding=\"shift-jis\" ?>"?> <? if($env=="E"){ echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML Basic 1.0//EN\" \"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd\">"; }elseif($env=="i"){ echo "<!DOCTYPE html PUBLIC \"-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.2) 1.0//EN\" \"i-xhtml_4ja_10.dtd\">"; }elseif($env=="S"){ echo "<!DOCTYPE html PUBLIC\"-//WAPFORUM//DTD WML 2.0//EN\" \"http://www.wapforum.org/wml20.dtd\">"; }?> <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"> <head> <meta name="ibm:devicetype" content="i-mode6_foma"> <meta http-equiv="content-style-type" content="text/css" /> <meta http-equiv="cache-control" content="no-cache"> <?php if($env=="i"){ echo"<style type=\"text/css\">"; echo"a:visited{color:#0000ff;}"; echo"</style>"; }else{ echo"<style type=\"text/css\">"; echo"#font{font-size:12px; color:red;}"; echo"#ffffont{color:brown;}"; echo"#back{background-color:#b0c4de;}"; echo"</style>"; } ?> <title>まつ毛</title> </head> <body link="#0000ff" vlink="#0000ff"> <br /> <br /> <div style="text-align: center;"> <img src="<?=$titleg?>"> <br /> </div> <br /> <br /> <?php if($env=="i"){echo "<hr style=\"border-style:solid; border-color:#000000;\"/>";} else{echo"<hr color=\"#000000\"; />";} ?> <div style="text-align: center;"> <div style="background-color:#000000; color:black;"> まゆげまつげ </div> </div> <?php if($env=="i"){echo "<hr style=\"border-style:solid; border-color:#b0c4de;\"/>";} else{echo"<hr color=\"#b0c4de\"; />";} ?> <br /> <br /> <hr style="border-style:solid; border-color:#000000;"/> <div style="background-color:#808df0f; color:000000;"> yahoo japan! </div>

    • ベストアンサー
    • HTML
  • PHPでheader情報がうまく表示できない

    ドコモ対応でXHTMLのヘッダー情報がうまく送れません。 PCからのテストで header('Content-Type: application/xhtml+xml'); をコード挿入すし、サイト表示の確認すると「ファイルのダウンロード 」ダイアログがでます。 header('Content-Type: application/xhtml+xml'); を入れずにテストするとダイアログはでません。 ・display.phpがメインページであくまでもskin.htmlをインクルードして置換しecho表示する感じなのですが・・・・・ 困っています。助けて下さい。 skin.html ----------------- <html> <body> <head> <!--%title--> </head> <body> コンテンツ </body> </html> ----------------- test.php -------------------------------------------------------------------------------------- 変数定義は省略 $html = file_get_contents($temp); $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/^DoCoMo/i", $agent)){ $html = str_replace( "<!--%title-->", $docomo, $html); header('Content-Type: application/xhtml+xml'); echo "$html"; } elseif(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]|SoftBank)/i", $agent)){ $html = str_replace( "<!--%title-->", $softbank, $html); header('Content-Type: application/xhtml+xml'); echo "$html"; } elseif(preg_match("/^KDDI\-/i", $agent) || preg_match("/UP\.Browser/i", $agent)){ $html = str_replace( "<!--%title-->", $au, $html); header('Content-Type: application/xhtml+xml'); echo "$html"; } else{ $html = str_replace( "<!--%title-->", $other, $html); header('Content-Type: application/xhtml+xml'); echo preg_replace('/{.*?}/', '', $html); -------------------------------------------------------------------------------------- display.php ------------------------------------------ <?php $temp = "./skin.html"; require_once('./test.php'); ?>

    • ベストアンサー
    • PHP
  • サイトが移動しました(301)が出てしまいます。

    以下のようにキャリア判別しましたが、ドコモ(f706i) でみるとサイトが移動しました(301)が出ます。 これはなんとかならないんでしょうか? <?php $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/^DoCoMo/i", $agent)){ header("Location: ​http://sample.com/i/index.html");​ exit; }else if(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]|SoftBank)/i", $agent)){ header("Location: ​http://sample.com/s/index.html");​ exit; }else if(preg_match("/^KDDI\-/i", $agent) || preg_match("/UP\.Browser/i", $agent)){ header("Location: ​http://sample.com/e/index.html");​ exit; }else{ header("Location: ​http://sample.com/pc/index.html");​ exit; } ?>

    • ベストアンサー
    • PHP
  • auの対応に困っています。

    auの対応に困っています。 先日から携帯サイトを作っていてau携帯からの投稿が文字化けしてしまいます。 例 あいうえお→%82%a0%82%a2%82%a4%82%a6%82%a8 下記ソースのどこに問題があるのでしょうか? わかるかた、どうぞよろしくお願いします。 <?php $agent=$_SERVER['HTTP_USER_AGENT']; if(preg_match("/DoCoMo/", $agent)) { print("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\n"); print ("<!DOCTYPE HTML PUBLIC \"-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.3) 1.0//EN\" \"i-xhtml_4ja_10.dtd\">\n"); print ("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"ja\" xml:lang=\"ja\">\n"); print ("<head>\n"); print ("<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=Shift_JIS\" />"); } elseif(preg_match("/KDDI\-/", $agent)||preg_match("/UP\.Browser/", $agent)) { print("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\n"); print ("<!DOCTYPE html PUBLIC \"-//OPENWAVE//DTD XHTML 1.0//EN\" \"http://www.openwave.com/DTD/xhtml-basic.dtd\">\n"); print ("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"ja\" xml:lang=\"ja\">\n"); print ("<head>\n"); print ("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\" />"); } elseif(preg_match("/J\-PHONE|Vodafone|MOT\-[CV]980|SoftBank/", $agent)) { print("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\n");つづきは省略

    • ベストアンサー
    • PHP
  • i Phone 用振り分け

    以下のように携帯キャリアごとに振り分け、3キャリア以外は PCフォルダに振り分けるようにした場合ですが、PCフォルダの方で i Phone 用に幅480pxで作成したページを配置すると PCから http://mypage.net/ でアクセスしたユーザーにも i Phone 用の幅480pxページを見せるようになってしまいますか? i Phoneやスマートフォンの対処はどうされているんでしょうか? <?php $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/^DoCoMo/i", $agent)){ header("Location: http://mypage.net/i/index.html"); exit; }else if(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]|SoftBank)/i", $agent)){ header("Location: http://mypage.net/s/index.html"); exit; }else if(preg_match("/^KDDI\-/i", $agent) || preg_match("/UP\.Browser/i", $agent)){ header("Location: http://mypage.net/e/index.html"); exit; }else{ header("Location: http://mypage.net/pc/index.html"); exit; } ?>

    • ベストアンサー
    • PHP
  • 携帯、スマートフォンのPHP振り分け

    こんなPHPを書いているのですが どうしてもParse errorが出ます。 解決方法を教えて下さい!! ■エラー内容 Parse error: syntax error, unexpected T_EXIT in /home/sites/heteml/users/web/m/index.php on line 5 ■振り分けPHP <?php $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/^DoCoMo/i", $agent)){ header("Location: ​http://www.hogehoge.com/m/i/index.html");​ exit; }else if(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]|SoftBank)/i", $agent)){ header("Location: ​www.hogehoge.com/m/s/index.html");​ exit; }else if(preg_match("/^KDDI\-/i", $agent) || preg_match("/UP\.Browser/i", $agent)){ header("Location: ​www.hogehoge.com/m/e/index.html");​ exit(); }else if(preg_match("iPhoneやスマートフォン用の判定", $agent)){ header("Location: www.hogehoge.com/m/smt/index.html"); exit(); }else{ header("Location: ​www.hogehoge.com/m/pc/index.html");​ exit(); } ?> よろしくお願い致します。

    • ベストアンサー
    • PHP
  • 携帯サイトを作成しているのですが、DOCTYPE宣言で

    携帯サイトを作成しているのですが、DOCTYPE宣言で <!DOCTYPE HTML PUBLIC \"-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.3) 1.0//EN\" \"i-xhtml_4ja_10.dtd\"> (ドコモ使用時) だけがページに表示されてしまいます。書き方に間違いがあるのでしょうか? 又、これは受け入れられてないのでしょうか? どなたかわかる方アドバイスよろしくおねがいします。 ↓プログラム添付 <?php $agent=$_SERVER['HTTP_USER_AGENT']; if(preg_match("/DoCoMo/", $agent)) { print("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\n"); print ("<!DOCTYPE HTML PUBLIC \"-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.3) 1.0//EN\" \"i-xhtml_4ja_10.dtd\">\n"); print ("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"ja\" xml:lang=\"ja\">\n"); print ("<head>\n"); print ("<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=Shift_JIS\" />"); } elseif・・・・

    • ベストアンサー
    • PHP
  • PHP 携帯・PC 振り分け

    こんにちはphpの振り分けについてご教授お願いします。 http://www.abc.jp/→PCサイト(/home/abc/www/の中身) http://m.abc.jp/→mobileサイト(/home/abc/www/mobile/の中身) とした場合、PCからmobileサイトにアクセスがあった場合pcサイトに飛ばし、携帯からPCサイトにアクセスがあった場合mobileサイトに飛ばすといったようなことをしたいのですが、下記の内容でdoctype宣言をおこなった場合どのように記述したらよろしいでしょうか? 下記の記述は別ファイルに記述し、index.phpまたは他の.phpに読み込まして各キャリアをdoctype宣言で振り分けしています。 下記の記述はネット上から見つけてきたものです。 http://www.kamitani79.com/2008/10/doctypephpssi.html <?php $agent=$_SERVER['HTTP_USER_AGENT']; if(preg_match("/DoCoMo/", $agent)) { print ("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\n"); print ("<!DOCTYPE html PUBLIC \"-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.3) 1.0//EN\" \"i-xhtml_4ja_10.dtd\">\n"); print ("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"ja\" xml:lang=\"ja\">\n"); print ("<head>\n"); print ("<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=Shift_JIS\" />"); } elseif(preg_match("/KDDI\-/", $agent)||preg_match("/UP\.Browser/", $agent)) { print ("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\n"); print ("<!DOCTYPE html PUBLIC \"-//OPENWAVE//DTD XHTML 1.0//EN\" \"http://www.openwave.com/DTD/xhtml-basic.dtd\">\n"); print ("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"ja\" xml:lang=\"ja\">\n"); print ("<head>\n"); print ("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\" />"); } elseif(preg_match("/J\-PHONE|Vodafone|MOT\-[CV]980|SoftBank/", $agent)) { print ("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\n"); print ("<!DOCTYPE html PUBLIC \"-//J-PHONE//DTD XHTML Basic 1.0 Plus//EN\" \"xhtml-basic10-plus.dtd\">\n"); print ("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"ja\" xml:lang=\"ja\">\n"); print ("<head>\n"); print ("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\" />"); } else { print ("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\n"); print ("<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\" \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">\n"); print ("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ja\">\n"); print ("<head>\n"); print ("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\" />"); } ?> ご教授お願いいたします。

    • ベストアンサー
    • PHP
  • Smartyを使用した、テンプレート内でのキャリア振り分け

    宜しくお願い致します。 現在モバイルサイトを構築しており、PHP+Smartyを利用しているのですが、テンプレート内で"if文"を利用した(ユーザーエージェントによる)キャリア振り分けをしたいと考えています。 ロジックとしては、PHPファイル内でユーザーエージェントを取得し、変数に適当な値を入れる。 その変数をassignし、テンプレート内ではき出す際に条件分岐。 と考えているのですが、うまくいきません。 ご教授いただけましたら幸いです。 なお、ソースは下記のようになります。 【carrier.php】※ディレクトリーの指定など一部省略 $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/^DoCoMo/i", $agent)){ $ca == "i"; }else if(preg_match("/^KDDI\-/i", $agent) || preg_match("/UP\.Browser/i", $agent)){ $ca == "ez"; }else if(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]|SoftBank)/i", $agent)){ $ca == "sb"; }else { $ca == "pc"; } $tpl->assign('ca','$ca'); $tpl->display('carrier.html'); 【carrier.html】 {if $ca == "ez"}ezです{/if}

    • ベストアンサー
    • PHP

専門家に質問してみよう