0

I have a database with names.
I have a PHP MySQL query that fetches names form that database.
These names include characters like ž, š, đ, č, ć, etc.

But when I run the Website these characters are displayed as this

I have a <meta charset="UTF-8"> in my header and the database was created with utf8_general_ci, and I also tried utf8_unicode_ci as well.

What can I do ?

EDIT: If I use utf8_encode for the echo it returns the name without the characters

2

5 Answers 5

1

You should set NAMES character set:

mysqli_query ($connection, "SET NAMES 'UTF-8'");
Sign up to request clarification or add additional context in comments.

Comments

0

try this

mysqli_set_charset ($connection, "utf8");

before executing query ...

Comments

0

I have these lines in my /etc/my.cnf under mysqld section

 [mysqld]
 init_connect='SET collation_connection = utf8_general_ci'
 init_connect='SET NAMES utf8'
 default-character-set=utf8
 character-set-server = utf8
 collation-server = utf8_general_ci

this will become a global setting if all your scripts need it

Comments

0

set CHARSET=utf8 in your database

Comments

0

Try:

PHP file add the following at the top of your code

<?php

   header('Content-Type: text/html; charset=utf-8');
?>

Connect MYSQL (http://php.net/manual/en/mysqli.set-charset.php)

$mysqli = new mysqli("localhost", "root", "", "test");
$mysqli->set_charset("utf8");

Note: Make sure your PHP script file is saved in UTF8

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.