鍦≒HP鐜涓厤缃娓湇鍔″櫒浠ユ敮鎸丟BK瀛楃闆嗘槸涓€涓父瑙佺殑闇€姹傦紝灏ゅ叾鏄湪澶勭悊涓枃鍐呭鏃躲€侴BK瀛楃闆嗘槸涓浗鍥藉鏍囧噯GB2312鐨勬墿灞曪紝鑳藉鏀寔鏇村鐨勬眽瀛楀拰绗﹀彿銆傛湰鏂囧皢璇︾粏浠嬬粛濡備綍鍦≒HP鐜涓厤缃娓湇鍔″櫒浠ユ敮鎸丟BK瀛楃闆嗐€?/p>
1. 妫€鏌ユ湇鍔″櫒鐜
纭繚浣犵殑棣欐腐鏈嶅姟鍣ㄥ凡缁忓畨瑁呬簡蹇呰鐨勮蒋浠跺拰鏈嶅姟銆傞€氬父鎯呭喌涓嬶紝PHP鐜浼氶粯璁ゅ畨瑁呭湪Linux绯荤粺涓婏紝鍥犳鎴戜滑闇€瑕佺‘璁や互涓嬪嚑鐐癸細
- 鏈嶅姟鍣ㄦ搷浣滅郴缁燂細閫氬父鏄疌entOS銆乁buntu绛塋inux鍙戣鐗堛€?/li>
- Web鏈嶅姟鍣細濡侫pache銆丯ginx銆?/li>
- PHP鐗堟湰锛氬缓璁娇鐢≒HP 7.x鎴栨洿楂樼増鏈€?/li>
浣犲彲浠ラ€氳繃SSH鐧诲綍鍒版湇鍔″櫒锛屽苟浣跨敤浠ヤ笅鍛戒护妫€鏌HP鐗堟湰锛?/p>
php -v
2. 淇敼PHP閰嶇疆鏂囦欢
涓轰簡浣縋HP鏀寔GBK瀛楃闆嗭紝浣犻渶瑕佷慨鏀筆HP鐨勯厤缃枃浠禶php.ini`銆傞€氬父锛岃繖涓枃浠朵綅浜巂/etc/php.ini`鎴朻/etc/php/7.x/apache2/php.ini`锛堟牴鎹甈HP鐗堟湰涓嶅悓鑰屾湁鎵€宸紓锛夈€?/p>
鎵惧埌骞剁紪杈慲php.ini`鏂囦欢锛屾坊鍔犳垨淇敼浠ヤ笅鍑犺锛?/p>
default_charset = "GBK"
mbstring.internal_encoding = "GBK"
mbstring.http_input = "GBK"
mbstring.http_output = "GBK"
mbstring.encoding_translation = On
杩欎簺璁剧疆纭繚PHP鍦ㄥ鐞嗗瓧绗︿覆鏃朵娇鐢℅BK缂栫爜锛屽苟涓斿湪杈撳叆杈撳嚭鏃惰繘琛岀浉搴旂殑缂栫爜杞崲銆?/p>
3. 瀹夎澶氬瓧鑺傚瓧绗︿覆鎵╁睍
涓轰簡鏇村ソ鍦板鐞咷BK瀛楃闆嗭紝寤鸿瀹夎PHP鐨勫瀛楄妭瀛楃涓叉墿灞曪紙mbstring锛夈€傝鎵╁睍鎻愪緵浜嗗澶氬瓧鑺傚瓧绗︾殑鏀寔锛岀‘淇濆湪澶勭悊GBK缂栫爜鏃朵笉浼氬嚭鐜颁贡鐮侀棶棰樸€?/p>
鍙互閫氳繃浠ヤ笅鍛戒护瀹夎mbstring鎵╁睍锛?/p>
sudo apt-get install php-mbstring 瀵逛簬Debian/Ubuntu绯荤粺
sudo yum install php-mbstring 瀵逛簬CentOS/RHEL绯荤粺
瀹夎瀹屾垚鍚庯紝閲嶅惎Web鏈嶅姟鍣ㄤ互浣挎洿鏀圭敓鏁堬細
sudo systemctl restart apache2 瀵逛簬Apache鏈嶅姟鍣?
sudo systemctl restart nginx 瀵逛簬Nginx鏈嶅姟鍣?/code>
4. 閰嶇疆Web鏈嶅姟鍣?/h2>
濡傛灉浣犱娇鐢ㄧ殑鏄疉pache鎴朜ginx浣滀负Web鏈嶅姟鍣紝杩橀渶瑕佺‘淇濇湇鍔″櫒閰嶇疆姝g‘鍦板鐞咷BK瀛楃闆嗐€?/p>
4.1 Apache閰嶇疆
缂栬緫Apache鐨勯厤缃枃浠讹紙閫氬父浣嶄簬`/etc/apache2/apache2.conf`锛夛紝骞跺湪閫傚綋浣嶇疆娣诲姞浠ヤ笅鎸囦护锛?/p>
AddDefaultCharset GBK
杩欏皢纭繚Apache鍦ㄥ彂閫佸搷搴旀椂浣跨敤GBK缂栫爜銆?/p>
4.2 Nginx閰嶇疆
瀵逛簬Nginx锛岀紪杈戦厤缃枃浠讹紙閫氬父浣嶄簬`/etc/nginx/nginx.conf`鎴栫珯鐐归厤缃枃浠讹級锛屽苟鍦℉TTP鍧椾腑娣诲姞浠ヤ笅鎸囦护锛?/p>
charset gb2312;
杩欏皢纭繚Nginx浣跨敤GBK缂栫爜鍙戦€佸搷搴斻€?/p>
5. 鏁版嵁搴撻厤缃?/h2>
濡傛灉鎮ㄧ殑搴旂敤绋嬪簭娑夊強鏁版嵁搴撴搷浣滐紝纭繚鏁版嵁搴撲篃鏀寔GBK瀛楃闆嗐€備互MySQL涓轰緥锛屼綘鍙互鍦ㄥ垱寤烘暟鎹簱鎴栬〃鏃舵寚瀹氬瓧绗﹂泦涓篏BK锛?/p>
CREATE DATABASE mydb CHARACTER SET gbk COLLATE gbk_chinese_ci;
CREATE TABLE mytable (...) DEFAULT CHARSET=gbk;
鍦ㄨ繛鎺ユ暟鎹簱鏃讹紝纭繚璁剧疆浜嗘纭殑瀛楃闆嗭細
$conn->set_charset("gbk"); // 瀵逛簬MySQLi
mysqli_set_charset($conn, "gbk"); // 瀵逛簬MySQLi杩囩▼寮?/code>
6. 娴嬭瘯閰嶇疆
瀹屾垚涓婅堪閰嶇疆鍚庯紝寤鸿杩涜娴嬭瘯浠ョ‘淇濅竴鍒囨甯稿伐浣溿€傚垱寤轰竴涓畝鍗曠殑PHP椤甸潰锛岃緭鍑轰竴浜涘寘鍚獹BK瀛楃鐨勫唴瀹癸紝骞舵煡鐪嬫槸鍚﹁兘姝g‘鏄剧ず銆備緥濡傦細
<?php
header('Content-Type: text/html; charset=GBK');
echo "浣犲ソ锛屼笘鐣岋紒";
?>
濡傛灉椤甸潰鑳藉姝g‘鏄剧ず涓枃瀛楃锛屽垯璇存槑閰嶇疆鎴愬姛銆?/p>
閫氳繃浠ヤ笂姝ラ锛屾偍搴旇鑳藉鍦≒HP鐜涓垚鍔熼厤缃娓湇鍔″櫒浠ユ敮鎸丟BK瀛楃闆嗐€傜‘淇濇墍鏈夌浉鍏崇粍浠讹紙PHP銆乄eb鏈嶅姟鍣ㄣ€佹暟鎹簱锛夐兘姝g‘閰嶇疆锛屽苟杩涜浜嗗厖鍒嗙殑娴嬭瘯銆傝繖鏍峰彲浠ラ伩鍏嶅湪澶勭悊涓枃鍐呭鏃跺嚭鐜颁贡鐮佹垨鍏朵粬瀛楃缂栫爜闂銆?/p>
本文由阿里云优惠网发布。发布者:编辑员。禁止采集与转载行为,违者必究。出处:https://aliyunyh.com/76172.html
其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。