简体   繁体   中英

php unicode UTF-8 result in required files

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

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

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:

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

worked 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>

output result :

تواصل معنا 

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

Fist where did you set the variable $abspath ?

Then you have to put <?php and ?> tags around your require statemet and in your config file around your php!

Now the example below works fine for me and is pretty much the same as yours!

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>

And the Output is:

تواصل معنا 

Did you try after establishing connection to the database execute:

set_charset ( "utf8")

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM