1

So i still get "?" on special caracthers, like "ã"...

here is the start of my index.php:

<?php
header('Content-Type: text/html; charset=UTF-8');
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>INNPORT</title>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="dist/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
  <link rel="stylesheet" href="dist/css/estilos.min.css">
  <link rel="stylesheet" href="dist/css/skins/skin-blue.min.css">
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
  <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
  <link rel="stylesheet" type="text/css" media="screen" href="http://tarruda.github.com/bootstrap-datetimepicker/assets/css/bootstrap-datetimepicker.min.css">

The results im printing, i get them with a php query, and i print them on a for each... But i still get strange carachters. Here is my database:

https://i.stack.imgur.com/BzBzg.jpg

What am i doing wrong?

For example:

$query = "SELECT * FROM credenciais_sensores where ambiente = '1'";
    $results2 = mysqli_query($conn, $query);
<?php

                 foreach ($results2 as $result){
                       $local = $result['local'];
                   echo "<li><a class='clsPostData1' data-local='".$result['local']."' data-salaid='".$result['salaid']."' data-salakey='".$result['salakey']."'href='#'><span class='fontsala'>".$local."</a></li>";
                   }
          ?>

The $local variable have special caracthers, and its not dispalying them...

  • did you try viewing it to database and see its value? – Beginner Dec 16 '16 at 04:56
  • what do you mean? – Emerenciana Dec 16 '16 at 04:57
  • I mean did you try viewing it's value from your database see if its not been encoded – Beginner Dec 16 '16 at 04:58
  • on the database is it displaying "ã" just fine... by the away, i make the query with php, then i save the values on a form, and then i use javascript to receive those values... – Emerenciana Dec 16 '16 at 05:00
  • can you include the code where you displayed it – Beginner Dec 16 '16 at 05:01
  • what is the result when you debug it `var_dump($local);` – Beginner Dec 16 '16 at 05:10
  • it shows the "?"... "Pipo 08 - Ambiente N�o Controlado" – Emerenciana Dec 16 '16 at 05:13
  • Is the database using UTF-8? Are the tables in the database using UTF-8? Is the content of the database (the content you're pulling) SAVED as UTF-8? Is the connection to the database UTF-8? – junkfoodjunkie Dec 16 '16 at 05:13
  • did you try `htmlentities` function? – Beginner Dec 16 '16 at 05:20
  • Using `htmlentities` is a very bad approach if your charset is broken, it's better to fix the actual source of your issue, the charset being different around your application - set everything to UTF-8 instead. @Emerenciana have a look at this: http://stackoverflow.com/a/33906476/4535200 - likely it's the PHP header and/or the charset on the connection. – Qirel Dec 16 '16 at 05:24

1 Answers1

0

1) Run this query in your database (eg: PHPMyadmin) and make sure everything (except "character_set_filesystem" has a value of "utf8". If not, you have some fixing of your database to do before going any further:

SHOW VARIABLES LIKE 'character_set_%';

2) Run this query in your database (eg: PHPMyadmin) and make sure everything has a value starting with "utf8_". If not, fix your database settings before going any further:

SHOW VARIABLES LIKE 'collation_%';

3) Add this line to the start of your PHP code, after the db connection is established, but before any database query is executed:

mysqli_set_charset($conn, 'utf8');

4) Profit

sg-
  • 2,196
  • 1
  • 15
  • 16