Heim  >  Artikel  >  php教程  >  php文字符和显示乱码问题的解决方法

php文字符和显示乱码问题的解决方法

WBOY
WBOYOriginal
2016-06-06 19:55:401267Durchsuche

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 php中文字符写库和显示乱码问题的解决方法: 这个的问题就出在在php里没有告诉mysql数据库你要插入的数据是gbk类型的,要解决其实很简单.连接数据库后加上这么一句话就OK了. 大家以后在编写过程中, 一

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

    php中文字符写库和显示乱码问题的解决方法:

    这个的问题就出在在php里没有告诉mysql数据库你要插入的数据是gbk类型的,要解决其实很简单.连接数据库后加上这么一句话就OK了.

    大家以后在编写过程中, 一定要记得定义字符类型.

    mysql_query(“set names 'gbk‘”)

    下面是实例代码:

   

    /*

    filename:query.php

    do:get and show the data

    author:www.phpzixue.cn

    */

    include_once(“conn.php”);

    include_once(“include.php”);

    mysql_query(“set names 'gbk’”)or die(“设置字符库失败\n”);

    mysql_select_db($db)or die(“连接数据库失败!\n”);

    $exec = “select * from $table”;

    //echo $exec;

    $result = mysql_query($exec,$conn)or die(“查询数据库失败\n”);

    echo “

”;

    for($cout=0;$cout

    $city = mysql_result($result,$cout,city);

    $name = mysql_result($result,$cout,name);

    $phone = mysql_result($result,$cout,phone);

    echo “

”;

    echo “city: $city”;

    echo “name: $name”;

    echo “phone: $phone”;

    echo “

”;

    }

    echo “

”;

    ?>

php文字符和显示乱码问题的解决方法

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:php生成静态htmlNächster Artikel:php递归返回值的问题