0

I have a Netherlands texts saved in my table. They show well in MySQL table like this Wilt u hoogstens één of twee kinderen, ook al kunt u zich qua gezondheid en inkomen meer kinderen permitte

When I select that text and do an echo with PHP I get Wilt u hoogstens ��n of twee kinderen, ook al kunt u zich qua gezondheid en inkomen meer kinderen permitte.

I tried to set the PHP page to use <meta http-equiv="content-type" content="text/html; charset=utf-8"> and also tried to do echo utf8_decode($text) but the text is still not showing as in the table. Any help on this please? Thanks.

Note: the table field collation where the text is stored is utf8mb4_general_ci

To select the text from my table I'm using PHP PDO:

function get_questions($userBrowserLanguage, $dbh) {
$query = "SELECT Frage, FrageNr FROM `tbl_fragen` WHERE Language = ? AND Test = ? AND Frage != ? ORDER BY FrageNr ASC";
    $parameters = array('nl', 'OCA55', '');//$userBrowserLanguage
    $sth = do_query($query, $parameters, $dbh);
    $questions = array();
    while ($question = do_fetch_result($sth)) {
        array_push($questions, array($question['FrageNr'], $question['Frage']));
    }
    return $questions;
}
Dev Dev
  • 314
  • 4
  • 17
  • Try by adding this `header('Content-type: text/html; charset=utf-8');` in your php code before `echo` and this in `` the html head part – Haridarshan May 22 '21 at 18:46
  • I did and it gives me Wilt u hoogstens ??n – Dev Dev May 22 '21 at 18:49
  • Can you please share the code, how you're selecting that text and doing an `echo` – Haridarshan May 22 '21 at 18:52
  • I did edit the post to show that. – Dev Dev May 22 '21 at 18:55
  • 3
    Study the accepted answer to this question and ensure you've completed all the steps: [UTF-8 all the way through](https://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – ADyson May 22 '21 at 18:56
  • @DevDev follow the link which @ADyson has shared, it's seems when you're creating the connection with database you're not setting the charset to `utf8mb4` – Haridarshan May 22 '21 at 18:59
  • @Haridarshan you were right, adding this $dbh->query("SET NAMES utf8mb4"); solved the issue – Dev Dev May 22 '21 at 19:08
  • You don't need that in PDO, just set the encoding with the `charset` attribute in the DSN string. That also allows client side code to be aware of the encoding settings. – Álvaro González May 23 '21 at 12:03

0 Answers0