encoding - displaying EURO symbol and more - UTF-8 charset
this is driving me bonkers. I have a column in my table with all currency symbols and am trying to display them but to no avail.
my page is set as utf8
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
I have tried mb_convert_encoding, utf8_encode but cant seem to s=get it to display correctly.
At the moment I have
function isUTF8($str) {
if ($str === mb_convert_encoding(mb_convert_encoding($str, "UTF-32", "UTF-8"), "UTF-8", "UTF-32")) {
return true;
} else {
return false;
}
}
echo ( isUTF8( $ar['currrency_symbol'] ) ? $ar['currrency_symbol'] : mb_convert_encoding( $ar['currrency_symbol'], 'UTF-8' ) );
which also doesn't work.
any help is much appreciated.
EDIT
function get_currency_symbol( $code ) {
$con = Database::getInstance();
$re = $con->query("SELECT * FROM `countryinfo` WHERE currency_code = '$code'");
if( $re->num_rows == 0 ) {
return '£';
}
$ar = $re->fetch开发者_如何转开发_assoc();
echo ( isUTF8( $ar['currrency_symbol'] ) ? $ar['currrency_symbol'] : mb_convert_encoding( $ar['currrency_symbol'], 'UTF-8' ) );
//return iconv( mb_detect_encoding( $ar['currrency_symbol'] ), 'UTF-8//TRANSLIT', $ar['currrency_symbol'] );
}
///
abstract class Database {
private static $instance = NULL;
private function __clone() {}
public function __construct() {}
public static function getInstance() {
if ( NULL === self::$instance ) {
self::$instance = new MySQLi( DBSERVER, DBUSER, DBPASS, DBNAME );
}
self::$instance->query("SET NAMES 'utf8'");
return self::$instance;
}
public function kill_con() {
self::$instance->close();
}
}
It could help to convert your document to UTF-8 (without BOM) using for example Notepad++.
In case you are using a database to fetch the data, execute the following query before all other queries:
mysql_query("SET NAMES 'UTF8'");
Do you use PDO for your database connection? If yes, try using:
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
As a an option when creating the connection.
See: http://www.php.net/manual/de/pdo.construct.php -> $driver_options
精彩评论