ホームページ >バックエンド開発 >PHPチュートリアル >通行人の皆様、Xiaocai がこのコードを読むのを手伝ってください。
UA で言語エンコーディング情報を取得してジャンプしたい 機能: UA に非 zh-CN エンコーディングが含まれている場合、言語情報が設定されていない場合はジャンプしません。関数を自分で確認しました。今日の午後、実験はまだ成功していません。「いいえ」を大量に出力する方法がわかりません。シャオニウさん、ありがとう!
$ua = $_SERVER['HTTP_USER_AGENT']; $lang = array("af-ZA","sq-AL","ar-DZ","ar-BH","ar-EG","ar-IQ","ar-JO","ar-KW","ar-LB","ar-LY","ar-MA","ar-OM","ar-QA","ar-SA","ar-SY","ar-TN","ar-AE","ar-YE","hy-AM","az Azeriaz-AZ-Cyrl","az-AZ-Latn Azeri","eu-ES","be-BY","bg-BG","ca-ES","zh-HK","zh-MO","zh-CN","zh-CHS","zh-SG","zh-TW","zh-CHT","hr-HR","cs-CZ","da-DK","div-MV","nl-BE","nl-NL","en-AU","en-BZ","en-CA","en-CB","en-IE","en-JM","en-NZ","en-PH","en-ZA","en-TT","en-GB","en-US","en-ZW","et-EE","fo-FO","fa-IR","fi-FI","fr-BE","fr-CA","fr-FR","fr-LU","fr-MC","fr-CH","gl-ES","ka-GE","de-AT","de-DE","de-LI","de-LU","de-CH","el-GR","gu-IN","he-IL","hi-IN","hu-HU","is-IS","id-ID","it-IT","it-CH","ja-JP","kn-IN","kk-KZ","kok-IN","ko-KR","ky-KZ","lv-LV","lt-LT","mk-MK","ms-BN","ms-MY","mr-IN","mn-MN","nb-NO","nn-NO","pl-PL","pt-BR","pt-PT","pa-IN","ro-RO","ru-RU","sa-IN","sr-SP-Cyrl","sr-SP-Latn","sk-SK","sl-SI","es-AR","es-BO","es-CL","es-CO","es-CR","es-DO","es-EC","es-SV","es-GT","es-HN","es-MX","es-NI","es-PA","es-PY","es-PE","es-PR","es-ES","es-UY","es-VE","sw-KE","sv-FI","sv-SE","syr-SY","ta-IN","tt-RU","te-IN","th-TH","tr-TR","uk-UA","ur-PK","uz-UZ-Cyrl","uz-UZ-Latn","vi-VN");for($i=0;$i<136;$i++){if(is_numeric(stripos($ua,$lang[$i])) == false){ echo "no";}else{ echo "yes";}}
要件は、中国人はリダイレクトされず、中国人以外はリダイレクトされるという要件ですか?
クライアントのブラウザで使用される言語の取得は、$_SERVER["HTTP_ACCEPT_LANGUAGE"] からインターセプトする必要があります。
たとえば、
if (preg_match("/zh/i", substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4))) { echo "不跳转";}else { echo "跳转";}
HTTP_ACCEPT_LANGUAGE は、実際にはクライアント オペレーティング システムのデフォルトの文字セットを反映しており、ユーザーがブラウザを参照するために使用する文字セットとは関係ありませんウェブページ
中国語を話せなんて誰が言ったのですか? ブラウザでは純粋な英語の Web サイトを表示できないのですか?
次に、要件は非 zh エンコーディング ジャンプです。すべての可能性をリストする必要はありません。stripos を使用して一度だけ決定してください。
最後に、foreach を試してください。アレイ
最初に投げ続けます
UA の取得とブラウザの取得は 2 つのアイデアです
両方を行う必要があります、foreach は非常に便利です