Jump to content

Recommended Posts

Posted

Hi!

 

I'm a spanish user of your free hosting.

 

My problem is that i can't view on my website spanish specials chars, like á, ñ, é...

 

I have uft8 charset, utf8_spanish_ci collate and i can see the special chars on my website, but not from mysql. What is my problem?

 

Thanks!!

Posted

Hi there,

 

I'm not staff but I think I might be able to help you. :)

 

Database

While it's probably better to be consistent, database collations don't really matter. Just tested that.

 

PHP

Let's make sure PHP is ready to display unicode characters.

 

Tell your database connection to use utf8 after connecting:

<?php

// Establish database connection
$db = new mysqli($dbHost, $dbUser, $dbPassword, $dbName);
$db->set_charset('utf8');

// Catch any connection errors
if ($db->connect_errno) {
   die('DB Error: ' . $db->connect_error);
}

 

Escape database data before outputting to a web page:

<?php

// Require database connection file
require_once 'database.php';

// Create escape function
function e($string) {
   return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
}

// Getting data from database
$data = $db->query("SELECT * FROM guestbook");

// Escape and output to page
while ($row = $data->fetch_assoc()) {
   echo e($row['message']) . '<br>';
}

 

HTML

Define your charset in the head of your HTML:

<meta charset="utf-8">

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...