Page showing interrogation and bench showing accent?

Asked

Viewed 1,431 times

1

On my page, if I type some accent inside some tag, it is shown normal; If I send some accent via form to the bank, in the table appears (á) and in the page appears the normal accent. (á) ; If I insert directly into the table a data with accent Ex: (á), in the bank appears (á) and on the site appears the question mark. ( ) How do I show accent in everything? I’m using PHP and mysql.

  • Both bank and website are UTF-8.

3 answers

1

You should check which ENCODING is using in HTML and the database, and making the necessary changes to use it ENCODING both of us.

The most recommended currently is to use UTF-8 to prevent headaches (you can read more about it here)


Then in HTML you define UTF-8 using the meta tag as an example:

<html>
<head>
    <meta charset="UTF-8">
// resto do código

In Mysql you can check the ENCODING current with query (source here):

SELECT default_character_set_name FROM information_schema.SCHEMATA 
WHERE schema_name = "schemaname";

If your database is not in UTF-8, you will have two options:

  • Set the same database encoding on HTML pages
  • Update database to use UTF-8

I confess that update the ENCODING database can be a bit boring, but I find it better than using another ENCODING.

1

Before entering the data into the database you need to use the UTF8 standard, try as follows;

$VARIABLE = Utf8_decode("TEXT");

done this you can already enter the data in the database, if it has not worked will need to check the pattern to which your bank is configured and change to the same pattern of your page. PHP documentation.

0

Opa...

You can do this in many ways... You can set it in PHP itself by placing it at the beginning of the document

<?php header("Content-type: text/html; charset=utf-8"); ?>

You can speed up the output of data directly from the Mysql:

mysql_set_charset('utf8');

PDO:

$handle = new PDO("mysql:host=localhost;dbname=nomebanco",
'usuario', 'senha',
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

In case the problem is only happening with the HTML, is resolved simply by setting the UTF of the page, or the UTF-8 or the code ISO-8859-1...

It can also do the hard way, with the str_replace:

$string="Téstè! Hasta Mañana!";
function retiraAcentos($string){
return preg_replace(array("/(á|à|ã|â|ä)/","/(Á|À|Ã|Â|Ä)/","/(é|è|ê|`ë)/","/(É|È|Ê|Ë)/","/(í|ì|î|ï)/","/(Í|Ì|Î|Ï)/","/(ó|ò|õ|ô|ö)/","/(Ó|Ò|Õ|Ô|Ö)/","/(ú|ù|û|ü)/","/(Ú|Ù|Û|Ü)/","/(ñ)/","/(Ñ)/"),explode(" ","a A e E i I o O u U n N"),$string);

}`

echo retiraAcentos($string);    

I hope I’ve helped in some way :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.