This question already has an answer here:
- UTF-8 all the way through 13 answers
How can I echo a sql text field into a paragraph?
My code does puts the text in but changes the accents like á
to this -> �
.
I tried adding UTF-8 in the header and removing it.
Removing UTF-A makes the sql content is ok but all the content outside the paragraph messes up.
I checked the DB was using (UTF-8-unicode), The files were saved with UTF-8
Any ideas on what might be wrong?
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<textarea class="texto" name="textoarticulo" id="textoarticulo" form="formarticulo" placeholder="Texto del artículo...">
<?
echo $row['txt4'];
?>
</textarea>
It's important that your entire code has the same charset to avoid issues where characters displays incorrectly.
Here's a little list of things that has to be set to a specific charset.
Headers
Setting the charset in both HTML and PHP headers to UTF-8
PHP (PHP headers has to be placed before any output: PHP echo, whitespace, HTML!):
HTML (HTML-headers are placed within the
<head>
/</head>
tag):Connection
You also need to specify the charset in the connection itself.
PDO (specified in the object itself):
MySQLi: (placed directly after creating the connection,
$mysqli
is the connection object)MySQL (depricated): (placed directly after creating the connection)
Database
Your database and its tables has to be set to UTF-8. Note that charset is not the same as collation.
You can do that by running the queries below once for each database and tables (for example in phpMyAdmin)
Caution... There are various different situations that need different
ALTERs
. Details Here . Doing the wrongALTER
is likely to make things worse. -- Rick Jamesphp.ini specification
In your
php.ini
file, you should specify the default charset for your platform, like this(This is in essence the same as doing
header('Content-Type: text/html; charset=utf-8');
on all pages)File-encoding
.php
file itself is UTF-8 encoded. If you're using Notepad++ to write your code, this can be done in the "Format" drop-down on the taskbar. You should use UTF-8 w/o BOM.Should you follow all of the pointers above, chances are your problem will be solved. If not, you can take a look at this StackOverflow post: UTF-8 all the way through.