PHP Unicode UTF-8生成所需文件 [英] php unicode UTF-8 result in required files

查看:68
本文介绍了PHP Unicode UTF-8生成所需文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将此define()函数添加到我的config.php文件中.

i add this define() function in my config.php file.

$options = DataAccess::FETCHLOAD("SELECT sign FROM " . OPTIONS . " WHERE 1");
define('_SIGN_',$options['0']['sign']);

现在,我required config.php文件进入我的index.php页面,如下所示:

Now, i required config.php file into my index.php page like this :

require $abspath .'/config.php';

  <!DOCTYPE html>
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  </head>
  <body>
  <?PHP echo _SIGN_; ?>
  </body>
  </html>

现在在输出中,我得到以下结果:

now in output i have this result:

?????????????????????

工作结果:

  <!DOCTYPE html>
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  </head>
  <body>
  $options = DataAccess::FETCHLOAD("SELECT sign FROM " . OPTIONS . " WHERE 1");
  define('_SIGN_',$options['0']['sign']);
  <?PHP echo _SIGN_; ?>
  </body>
  </html>

输出结果:

تواصل معنا 

当我需要config.php时,如何解决此问题以显示Unicode UTF-8?!

how do fix this for show unicode UTF-8 when i required config.php ?!

推荐答案

在建立与数据库的连接后尝试执行以下操作:

Did you try after establishing connection to the database execute:

set_charset ( "utf8")

我使用MySQLi并采用这种方式:

I use MySQLi and make it this way:

//-> conncecting to db
$mysqli = new mysqli ( $hostname, $username, $password, $db );

if ( $mysqli -> connect_errno ) {

    echo 'Failed to connect to MySQL: ' . $mysqli -> connect_error;

}

// change character set to utf8
if ( ! $mysqli -> set_charset ( "utf8") ) {

    printf ( "Error loading character set utf8: %s\n", $mysqli->error );
}

这篇关于PHP Unicode UTF-8生成所需文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆