0

$message is retrieved from mysql db

The db tables have utf8_general_ci as character encoding

The following is executed with each connection:

mysqli_query($this->link,"set character set utf-8");

The php file is encoded utf-8

$message=urlencode($message);

When the following command is used:

echo $response = file_get_contents
("https://api.telegram.org/botxxxxxxxxxxxxxx/sendMessage?chat_id=-100xxxxxxx&disable_web_page_preview=TRUE&parse_mode=markdown&text=". $message);
}

If retrieved $message is stored in English: it works

If $message is stored in Arabic: it doesn't work

If $message is entered in Arabic in the file itself (not retrieved from db): it works

What is wrong? I would appreciate your help!

Quest
  • 109
  • 6

2 Answers2

1

you need to config your MySQL DB character-set manually using phpMyadmin set it to "utf8" or programmatically when opening your connection try this code:

$dbcon = mysqli_connect("host","user","pass","db"); 
    mysqli_query($dbcon, "set character_set_server='utf8'");        
    mysqli_query($dbcon, "set names 'utf8'");   

you may need to check the messages in the DB tables and may need to re-enter your msgs to the DB again if it's misformatted because of the wrong char-set.

ALPANNA
  • 26
  • 3
  • Thanks, but both are already set (set character_set_server='utf8' + set names 'utf8'. I tried several things directly on the db - no success! – Quest Jan 05 '22 at 11:36
0

it looks like the reason is that the browser still treats $message as "WINDOWS-256" encoded. Everything else is UTF8 encoded!

So iconv resolved the issue.

$message=urlencode($message);

Should be:

$message=urlencode(iconv("WINDOWS-256", "UTF-8", $message));

I don't really know why, but it has done the trick!

Quest
  • 109
  • 6