PHP MySQL Greek Letters Showing Like? Marks

PHP MySQL Greek letters showing like ???? marks

try the following:

after you connect to the mysql, do this query to make sure that you are using UTF8:

mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");

make sure that in HTML (head) you are using the right encoding, try:

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

if this does not help, try different encoding, like ISO-8859-1

Cant retrieve greek characters from mysql database with PHP

Make sure your client connection is set for UTF8. Examples:

SQL

SET NAMES UTF8;

PHP MySQLi

mysqli_set_charset('utf8');

PHP PDO

$handle = new PDO("mysql:host=localhost;dbname=dbname",
'username', 'password',
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
));

PHP mysql (deprecated - do not use)

mysql_set_charset('utf8');

Wrangling Greek characters

In this , look for "question marks".

In particular, it suggest that these are the likely things to check for:

  • The bytes to be stored are not encoded as utf8/utf8mb4. Fix this.
  • The column in the database is CHARACTER SET utf8 (or utf8mb4). Fix this.
  • Also, check that the connection during reading is UTF-8.

The problem occurred when storing the data; the data is lost. This can be confirmed by doing SELECT HEX(col)... -- it will be all 3F, the hex for ?.

If there are still problems, please provide SHOW CREATE TABLE, SHOW VARIABLES LIKE 'char%', and the connection parameters.

Issue displaying Greek text from MySQL db using PHP

Are you expecting Άλλο Αίτημα? Do SELECT HEX(col)... -- This would be correct hex: CE86 CEBB CEBB CEBF 20...; this would be "double encoded": C38E E280A0 C38E C2BB C38E C2BB C38E C2BF 20...

Read about Mojibake and Double encoding.

Greek as question marks from json with php

There was a incorrect syntax on the mysqli_set_charset.
The correct part of the code is the below:

if( function_exists('mysql_set_charset') ){
mysqli_set_charset($con, 'utf8');
}else{
mysqli_query($con, "SET NAMES 'utf8'");
}

Greek letters in filename instead of full word

html_entity_decode — Convert HTML entities to their corresponding characters

<?php
$orig = "2021_ΑΘΑΝΑΣΙΟΣ ΛΑΜΠΡΙΔΗΣ.xlsx";
$text = html_entity_decode($orig);

echo $orig . PHP_EOL;
echo $text . PHP_EOL;
?>

Output: 72103715.php

2021_ΑΘΑΝΑΣΙΟΣ ΛΑΜΠΡΙΔΗΣ.xlsx
2021_ΑΘΑΝΑΣΙΟΣ ΛΑΜΠΡΙΔΗΣ.xlsx

Search function with Greek characters in MySQL

If you are able to change the character set of your column (or table) then set it to utf8_general_ci (link to manual):

ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8_general_ci;

With this character set (which is case insensitive, as denoted by _ci), accented characters have the same weight (the value used for collation), so they return true when compared with each other (link to manual):

Non-UCA collations have a one-to-one
mapping from character code to weight.
In MySQL, such collations are case
insensitive and accent insensitive.
utf8_general_ci is an example: 'a',
'A', 'À', and 'á' each have different
character codes but all have a weight
of 0x0041 and compare as equal.

mysql> SET NAMES 'utf8' COLLATE 'utf8_general_ci';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT 'a' = 'A', 'a' = 'À', 'a' = 'á';
+-----------+-----------+-----------+
| 'a' = 'A' | 'a' = 'À' | 'a' = 'á' |
+-----------+-----------+-----------+
| 1 | 1 | 1 |
+-----------+-----------+-----------+
1 row in set (0.06 sec)

Alternatively, or if you cannot alter the database configuration in this way, you could write a function to replace accented characters with their non-accented equivalents (i.e. é -> e) and write this into a dedicated search field (a full-text search field is recommended). Perform searches on this field and return the accented field to the application.

storing greek letters in mysql table?

Did you create your table like this?

  CREATE TABLE t1
(
col1 CHAR(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci
)


Related Topics



Leave a reply



Submit