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

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

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

欢迎进入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文字符和显示乱码问题的解决方法

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php生成静态htmlNext article:php递归返回值的问题