Page showing question mark and bank showing accent? [duplicate]

1

On my page, if I type some accent inside a tag, it is shown normal; If I send some accent via form to the bank, the table appears and the normal accent appears on the page. (The); If I enter directly into the table a data with accent Ex: (á), the bank appears (á) and the site appears the interrogation. ( ) How do I show accent at all? I'm using PHP and mysql.

    
asked by anonymous 01.10.2018 / 16:53

3 answers

1

You should check which ENCODING you are using in the HTML and database, and make the necessary changes to use the same ENCODING in both.

The most recommended currently is to use UTF-8 to avoid headaches (read more about #

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 the 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 have two options:

  • Defining the same database encoding in HTML pages
  • Update the database to use UTF-8

I confess that updating ENCODING of the database can be a bit annoying, but I think it's better than using another ENCODING .

    
01.10.2018 / 17:20
1

Before entering the data into the database you must use the UTF8 standard, try the following:

$ VARIAVEL = UTF8_decode ("TEXT");

Once you have done this, you can enter the data in the database, if it did not work, you will need to check the default that your bank is configured to and change to the same pattern as your page. PHP Documentation

    
01.10.2018 / 21:14
0

Opa ...

You can do this in several 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 stream the data output directly from the MySQL connection:

mysql_set_charset('utf8');

PDO :

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

If the problem is only occurring with HTML , resolve it by simply setting the page's UTF-8 or UTF-8 8859-1 ...

You can also do it the hard way with 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 have helped in some way:)

    
01.10.2018 / 21:23