Questions about PHP files and encodings

Source: Internet
Author: User
Tags mysql code what php
Questions about PHP files and encodings
1:php the encoding format of the code file itself, what will be the impact of GB or UTF8?
2:php code file is mixed, have GB and UTF8 will lead to what kind of bad result?
What is the string encoding format in 3:php language? (for example, C is ASCII, but C # is Unicode and I don't know what PHP is)
4:php code file encoding format and MySQL database character encoding format will lead to what bad results?
Does the encoding format of the 5:mysql itself affect the effect of text output to the page?

There seems to be a lot of problems, please advise, thank you very much. Must be in time to knot the points.

------Solution--------------------
1:php the encoding format of the code file itself, what will be the impact of GB or UTF8?
As long as the HTML language declaration does not conflict, there is no relationship

2:php code file is mixed, have GB and UTF8 will lead to what kind of bad result?
Most will be poor students "garbled", and make you confused

What is the string encoding format in 3:php language? (for example, C is ASCII, but C # is Unicode and I don't know what PHP is)
You decide.

4:php code file encoding format and MySQL database character encoding format will lead to what bad results?
Just tell MySQL what coding content is required, no bad results

Does the encoding format of the 5:mysql itself affect the effect of text output to the page?
No

------Solution--------------------
1. What is the effect of a person's blood type O or a?

2. A person's blood type is also O and a at some point is normal such as may produce a rare blood, most of the time direct death.

3.php you are the creator, how do you want to build?

4. Different will let you wear 1000 degrees of glasses can not see that the string of garbled what is ... Of course, the problem of modification of glasses will be solved.

5. The database is your magazine, if you are not shivering ... Then he would not be fired, he would stay honest until ... You feel excited enough, you have to output. This is the time to think about the coding format. The right solution is to consider all of the code's unity when building the silo, and everything is in place.


------Solution--------------------
It doesn't matter what the program file is encoded with, as long as it's compatible with ASCII. The key is that the database is stored with UTF-8.
------Solution--------------------
First the encoding format of the file itself is to be specified, and the project must be unified. Next is the parameter code also must specify unification, otherwise Chinese will garbled. Inconsistent with MySQL code, either set the MySQL database encoding set or transcode with PHP transcoding function, otherwise Chinese garbled
------Solution--------------------
The great God is here. (- -#)


The encoding of the literal constant string in the source code is directly controlled by the source code file encoding, for example:

$str = "How are you?";

1, if it is the three characters saved by GBK encoding, then the hard disk actually occupies 6 bytes.
2, if it is the three characters saved by UTF8 encoding, then the hard disk actually occupies more than 6 bytes.

If the file is UTF8 saved, then you want to convert the string to GBK and send it to the browser.

So Mb_convert_encoding ($str, "UTF8", "GBK") will get a GBK coded "Hello", and the effect of your call to this function is to tell the PHP interpreter: The byte in this string is UTF8 encoded, You have to interpret this byte in accordance with the UTF8 code and convert the three characters to 6 bytes encoded in GBK.

After the echo is output to the browser, and the content type tells the browser that the byte is GBK, follow the GBK encoding to interpret the 6 bytes.
------Solution--------------------
Look at your side said a little dizzy ....
CI code ... If not mistaken, should be English and so on ...
Sina's open platform does not know, but in general, the code should also be English and symbols, etc...

For ASCII characters below 127, including English and symbols, numbers, their ASCII code and UTF8 code are exactly the same ....
So there may not be a problem you're talking about needing unification.


discuss

Oh, upstairs explanation of true rape ~

In fact, the reality is this, my PHP project, using the CI framework, its code itself is ANSI-encoded, and then our project inside the call Sina's open platform interface, it provides the interface code is UTF-8, this is how good? Do you manually unify it all over again?

Please help the gods, thank you!

------Solution--------------------
What's the deal? Change to a unified code
Of course, you can also send a translator to the PHP section. PHP provides mb_string and iconv two function groups, all of which can solve your problem conveniently.
------Solution--------------------
Explore

1:php the encoding format of the code file itself, what will be the impact of GB or UTF8?
As long as the HTML language declaration does not conflict, there is no relationship

2:php code file is mixed, have GB and UTF8 will lead to what kind of bad result?
Most will be poor students "garbled", and make you confused

What is the string encoding format in 3:php language? (for example, C is ASCII, but C # is Unicode and I don't know what PHP is)
You decide.

Encoding of the 4:php code file ...

------Solution--------------------
discuss
1:php the encoding format of the code file itself, what will be the impact of GB or UTF8?
2:php code file is mixed, have GB and UTF8 will lead to what kind of bad result?
What is the string encoding format in 3:php language? (for example, C is ASCII, but C # is Unicode and I don't know what PHP is)

------Solution--------------------
discuss
However, there is a problem, is a project, if there is a part of the PHP file contains Chinese characters, such as to echo out some text to the page, and then another PHP file is also included in the language, but the file is UTF-8 encoded, in the output at the time according to the previous methods can be controlled, But when editing code with the IDE is more painful, such as NetBeans, to specify an item encoding format, if specified as ANSI, that UTF8 those pages are garbled when editing, if specified as UTF8 then the ANSI-encoded files are displayed as garbled, So it's inconvenient. Try again today vs.php, have not confirmed whether it is possible to circumvent the problem.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.