国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP如何解決亂碼的四種方法

asal 2017-01-03 14:38:06 420
abstrak:在我們每個人在開始學習php的時候,都經歷過一個痛苦的亂碼過程,手足無措。現在告訴大家四種方法,徹底避免亂碼。       第一類:文件亂碼        沒出指定編碼, 但目前瀏覽器有的是默認gbk,有的卻是默認是utf8,這就導致亂碼!     

在我們每個人在開始學習php的時候,都經歷過一個痛苦的亂碼過程,手足無措?,F在告訴大家四種方法,徹底避免亂碼。
       第一類:文件亂碼
        沒出指定編碼, 但目前瀏覽器有的是默認gbk,有的卻是默認是utf8,這就導致亂碼! 
         解決辦法:
       1、 入口文件的第一行 ,強制輸出(常用)!

<?php
                header("Content-type: text/html; charst=utf-8");

      2、 html模版head部分(常用)!

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

          第二類 數據庫亂碼

      1、數據庫本身創(chuàng)建的時候指定編碼(常用)

create table cz_category(
        cat_id smallint unsigned not null auto_increment primary key comment '商品類別ID',
        cat_name varchar(30) not null default '' comment '商品類別名稱',
        parent_id smallint unsigned not null default 0 comment '商品類別父ID',
        cat_desc varchar(255) not null default '' comment '商品類別描述',
        sort_order tinyint not null default 50 comment '排序依據',
        unit varchar(15) not null default '' comment '單位',
        is_show tinyint not null default 1 comment '是否顯示,默認顯示',
        index pid(parent_id)
)engine=MyISAM charset=utf8;

      如果是在phpmyadmin下創(chuàng)建的,那么就應該 

         2、 php連接mysql(常用)

<?php
function getField($table_name)
{
$link = mysql_connect('localhost','root','1234abcd');
mysql_query('use daxue');
mysql_query('set names utf8');
$result=mysql_query("desc {$table_name}");

更多關于PHP如何解決亂碼的方法請關注PHP中文網(m.miracleart.cn)其它文章!

Nota Keluaran

Penyertaan Popular