Accentuation problem when migrating to PHP7

Asked

Viewed 1,970 times

1

I’m wearing a leotard latin1 in the bank columns and iso-8859-1 on the pages, while it was on PHP5 it worked normal, but when migrating to PHP7 the accents began to give problems appearing this in place of each accent.

PHP7 has changed the way it works with accents compared to PHP5?

  • 4

    You deleted the other and recreated the same, that’s not a good use of the site. If a question takes negative, the right is to try to follow the guidelines in [Ask] and improve it by editing, not recreating the question

  • 1

    Your question doesn’t make much sense. I see no relation between the language version and the database encoding, the fact of migrating does not mean that it results in a problem, as long as they are under the same encoding.

  • now yes, you gave me a plausible explanation

2 answers

3


Not the coding of documents has nothing to do with the language, the language only processes and sends a processed file back to the user, when the connection to the database is something that by default is configured in the database and not in PHP.

The configuration of the database depends entirely on what the developer will want to do, here is an answer on the subject, although the photo is PHP in it is valid for any language that is facing the Web (ie generating pages):

Note that any version of PHP tries to maintain backward compatibility, so the new PHP7 features do not necessarily make older scripts incompatible, unless you are using a function or class that has previously been discontinued.

To explain better, in case mysqli is an API that makes PHP access the mysql database that can be on a separate port or server, its only problem would be if I was using functions that start like this mysql_, as they were part of the older API that was already marked as obsolete since the PHP 5.5.0 and was only available until 5.6 for the sake of backward compatibility. Now in version 7.0.0+ it has been removed and scripts written using it will no longer work.

Setting up the charset in the bank

Even if you do this (PDO):

$conn = new PDO('mysql:host=HOST;dbname=BANCO;charset=utf-8', 'USUARIO', 'SENHA');
$conn->exec('SET CHARACTER SET utf8');//Define o charset como UTF-8

Or this (mysqli):

$mysqli->set_charset('utf8')

It does not mean that you are setting up PHP, in fact you are sending a statement to the bank for it to return as the results were requested.

In the case of banks a traditional web page and php will be composed of 4 important things:

  • HTTP server (apache, Nginx, IIS, etc)
  • PHP language that interprets scripts and returns as response
  • database
  • Scripts .php that you wrote:

All 4 have to have the necessary encoding settings:

  • HTTP server: can be resolved in httpd.conf or . htaccess, although you do use header('Content-Type: ...'); PHP itself already solves, that is only necessary to configure for static files (which may actually be optional)
  • PHP Language: set the header('Content-Type: ...');
  • Database: must use the instruction SET CHARACTER SET ... or $mysqli->set_charset('...') to say what you expect
  • Scripts .php that you wrote: must be saved with the desired encoding, if it is UTF-8 use "UTF-8 without GOOD", if it is latin1 or similar save the scripts as ANSI or windows-1252 or iso-8859-1 or compatible.
  • What happened was like this, I migrated to PHP 7 and at the same time offered to host my sites in the clouds. It was more confusion, accented characters with ? I returned to the previous version. But I’m thinking this whole mess is because the migration to such a cloud has not yet been completed.

  • But thanks for your answer, once the migration to the clouds is over, I’ll be back with version 7

  • @Leocaracciolo this must have been a problem in Apache and not in PHP, your problem can be avoided following the step-by-step answer that I Linkei http://answall.com/a/43205/3635, is something I keep repeating to the person, set a header, or a meta-tag, or use utf8_encode/utf8_decode is just "patches", you have to do the step-by-step response, I created it myself by seeing many answers here on the site that really were just gambiarras, try to follow it and you will see that it is a matter of organizing things.

  • really, really grateful for the attention, at least there is someone with common sense on this site!!!

  • @Leocaracciolo I took the liberty of editing your question http://answall.com/q/197152/3635 and left an upvote. See you later.

  • You’re the man, thank you again!!!

  • I changed the charset to UTF8 and collation to utf8_general_ci and on the pages I put http-equiv="Content-Type" content="text/html; charset=utf-8. But it continues to appear . What else should I do?

  • I recommend heavily reading this article here. It won’t change what has to be done at each point of the configuration, but it will help you understand what is happening at each point: http://local.joelonsoftware.com/wiki/O_M%C3%Adnimo_absoluto_que_todos_programmeres_de_software_they need,_Absolutely,Positivamente_de_Saber_Sobre_Unicode_e_Conjuntos_de_Caracteres(Apologies!)

  • @jsbueno https://answall.com/a/43205/3635

  • the linked answer has nothing to do with the specific answers to that question (but they are related to the problem that prompted the question) - it has to do with being 2018, and people still act without understanding what was already considered a minimum to know how to work with accented characters (in any language) in an article 2003

  • @jsbueno I will explain otherwise to make it clear to you, there is a problem is the understanding of people, they do not even know what is coding (codec), if this is a problem that affects us until today then you should formulate a question with answer and detail the subject in them, there on the link I explained the step by step and why codec X does not work together with codec Y, now if it is to be more "comprehensive" do what I suggested to you (create a specific topic) and I guarantee that you will have many positive results.

Show 6 more comments

1

Very likely there is a conflict with the configuration of the environment. Because according to what you reported, in the previous environment everything was working. Moreover, PHP7 does not bring about changes that affect encoding/encoding in relation to PHP5. however, there may be some obsolete or removed function or parameter in this new version, which your system still uses and may be triggering errors that ultimately affect the way the system should handle encoding. If that is the case, there is no solution here as it requires a thorough diagnosis of your system. Despite this, there are certain basic and logical points that can solve

Mbstring

Check how are the settings for Mbstring. You should be aware of these parameters: http://php.net/manual/en/mbstring.configuration.php

A practical way is to rotate the phpinfo(); and compare information. http://php.net/manual/en/function.phpinfo.php

Web server

Also check the WEB server encoding settings. (Apache, Nginx, IIS, etc).

Database

Of course, you should also check the database settings if you have.

It may have occurred that you migrated to a database containing incompatible settings and caused data corruption or simply a conflict that can be fixed. In case of corruption has no magic, will have to redo from a secure backup. I find this unlikely. But it is an option if the previous ones, described above, do not solve.

Browser other questions tagged

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