0

I have a table in mysql called messages. I use the following code to call date from my table and print them.

<?php
$message_query = mysql_query(" SELECT `messages_id`, `from_id`, `message`, `date` FROM `messages` WHERE `group_hash`='$hash' ORDER BY `date` ASC ");

while($run_message = mysql_fetch_array($message_query)){
    $message = $run_message['message'];
    $print_message = substr($message, 0, 100);
}

 echo "$print_message"; 

?>

I use the function substr() to give me a certain number of characters of the message that will be displayed. Messages are writen in Greek language and stored in field message which has type = utf8_general_ci. Everything works fine and the message dispalyed correctly. The only problem is that when a word that is printed cutted off, I get at the end of the word a symbol like ? in a rombus. When the word that printed does not cutted off, I don't get it. Any idea how to fix this?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
33528
  • 372
  • 6
  • 12
  • 30
  • Don't use the `mysql_*` functions. They have been deprecated since v5.5 (Jun 2013) and removed since v7.0 (Dec 2015). Instead use the [**mysqli_***](https://secure.php.net/manual/en/book.mysqli.php) or [**PDO**](https://secure.php.net/manual/en/book.pdo.php) functions with [**prepared statements**](https://secure.php.net/manual/en/pdo.prepare.php) and [**bound parameters**](https://secure.php.net/manual/en/pdostatement.bindparam.php). – Alex Howansky May 03 '17 at 18:23
  • 1
    Your encoding is obvioulsy `utf-8`? – u_mulder May 03 '17 at 18:24
  • yes sometimes i get something like "διάβασε τις σελίδε� " other times if the word is not cutted off i get "διάβασε τις σελίδες ." – 33528 May 03 '17 at 18:26

0 Answers0