【问题标题】:php unicode UTF-8 result in required filesphp unicode UTF-8 生成所需文件
【发布时间】:2014-10-28 18:57:56
【问题描述】:

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

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

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

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>

现在在输出中我有这个结果:

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

工作结果:

  <!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 ?!

【问题讨论】:

  • 数据库中该表的字符集是什么?
  • @Machavity:UTF-8。请看我的编辑。
  • @o-O 你在哪里设置 '$abspath' ?

标签: php mysql unicode utf-8


【解决方案1】:

你在哪里设置变量$abspath

然后你必须将&lt;?php?&gt; 标签放在你的require statemet 和你的php 配置文件中!

现在下面的例子对我来说很好,和你的几乎一样!

config.php:

<?php

    $options['0']['sign'] = "تواصل معنا";  //$options = DataAccess::FETCHLOAD("SELECT sign FROM " . OPTIONS . " WHERE 1");
    define('_SIGN_', $options['0']['sign']);


?>

index.php:

<?php require 'config.php'; ?>

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

输出是:

تواصل معنا 

【讨论】:

  • 这也是我的工作。但不适用于数据库检索数据。
【解决方案2】:

您是否在建立与数据库的连接后尝试执行:

set_charset ( "utf8")

我使用 MySQLi 并以这种方式实现:

//-> 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 );
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 2014-09-02
    • 1970-01-01
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多