search
HomeBackend DevelopmentPHP Tutorial 关于PHP文件及编码的有关问题

关于PHP文件及编码的问题
1:PHP代码文件本身的编码格式,是GB或者UTF8会影响什么?
2:PHP代码文件中是混杂的,有GB又有UTF8会导致什么样的不好结果么?
3:PHP语言中的字符串编码格式是什么?(比如C语言就是ASCII,但C#就是UNICODE,不知道PHP是什么)
4:PHP代码文件的编码格式跟MYSQL的数据库字符编码格式不同会导致什么不好的结果么?
5:MYSQL本身的编码格式会影响输出到页面上的文字的效果么?

问题好像有点多了,请大家指教,非常感谢.一定及时结帖给分.

------解决方案--------------------
1:PHP代码文件本身的编码格式,是GB或者UTF8会影响什么?
只要与 html 语言声明不冲突,就没有关系

2:PHP代码文件中是混杂的,有GB又有UTF8会导致什么样的不好结果么?
多半会差生“乱码”,而使你无所适从

3:PHP语言中的字符串编码格式是什么?(比如C语言就是ASCII,但C#就是UNICODE,不知道PHP是什么)
由你决定

4:PHP代码文件的编码格式跟MYSQL的数据库字符编码格式不同会导致什么不好的结果么?
只要通知 mysql 需要什么编码的内容,没有不好的结果

5:MYSQL本身的编码格式会影响输出到页面上的文字的效果么?
不会

------解决方案--------------------
1.一个人的血型是 O 或者A 会有什么影响?

2.一个人的血型又是O 又是A 某个时候是正常的 比如可能产生了稀有血液,大多数时候是直接死亡。

3.php你就是造物主 你想怎么造就怎么造.

4.不同会让你戴上1000度的眼镜也无法看明白那串乱码到底是什么... 当然改造一下眼镜问题也就解决了。

5.数据库就是你的弹仓,如果你不一哆嗦...那么他不会发射出来,他会老老实实的呆着,直到....你觉得足够兴奋,你要输出了.这个时候你才要考虑编码格式的事情.正确的解决方法就是 在建这个弹仓的时候 先考虑好所有编码的统一,就万事具备了。


------解决方案--------------------
程序文件用什么编码无所谓,只要兼容ASCII就行。关键是数据库存储用UTF-8就行
------解决方案--------------------
首先文件本身的编码格式要指定,并且项目中要统一。其次就是参数编码也要指定统一,否则中文会乱码。与mysql的编码不一致,要么设置mysql数据库的编码集要么用php转码函数转码,否则中文乱码
------解决方案--------------------
大神来了。(- -#)


源代码中的字面常量字符串的编码直接受源代码文件编码控制,举例:

$str = "你好吗";

1,如果是GBK编码保存的这三个汉字,那么硬盘上实际占用了6个字节。
2,如果是UTF8编码保存的这三个汉字,那么硬盘上实际占用了超过6个字节。

假如文件是UTF8保存的,那么你希望转化这个字符串为GBK的,并发给浏览器。

那么mb_convert_encoding($str, "utf8", "gbk")就会得到一个gbk编码的“你好吗”,而你这个函数的调用的效果就是告诉PHP解释器:这个字符串里的字节是UTF8编码的,你得按照UTF8编码解释这一段字节,并将这三个字符转化成GBK编码的6个字节。 

之后echo输出到浏览器,并content type告诉浏览器这一段字节是gbk的,请按照gbk编码去解释这6个字节。
------解决方案--------------------
看了你这边说的有点晕....
CI的代码...如果没有记错,应该都是英文等...
新浪的开放平台不知道,但是一般情况下,代码也应该都是英文及符号等....

对于127以下的ascii字符,包括英文及符号,数字, 他们的ascii码和utf8码是完全一样的....
所以可能不存在你说的需要统一的问题


探讨

呵呵,楼上的解释真油菜~

其实现实情况是这样的,我的一个PHP项目,使用的是CI框架,它的代码本身是ANSI编码的,然后我们的项目里面又调用了新浪的开放平台接口,它提供的接口代码又是UTF-8的,这该如何是好?难道手动统一一遍?

请大神们救命~谢谢

------解决方案--------------------
怎么处理?改成统一的编码
当然你也可以给 php 部分请个翻译。php 提供了 mb_string 和 iconv 两个函数组,都可以方便的解决你的问题
------解决方案--------------------
探讨

1:PHP代码文件本身的编码格式,是GB或者UTF8会影响什么?
只要与 html 语言声明不冲突,就没有关系

2:PHP代码文件中是混杂的,有GB又有UTF8会导致什么样的不好结果么?
多半会差生“乱码”,而使你无所适从

3:PHP语言中的字符串编码格式是什么?(比如C语言就是ASCII,但C#就是UNICODE,不知道PHP是什么)
由你决定

4:PHP代码文件的编码……

------解决方案--------------------
探讨
1:PHP代码文件本身的编码格式,是GB或者UTF8会影响什么?
2:PHP代码文件中是混杂的,有GB又有UTF8会导致什么样的不好结果么?
3:PHP语言中的字符串编码格式是什么?(比如C语言就是ASCII,但C#就是UNICODE,不知道PHP是什么)

------解决方案--------------------
探讨
可是还是碰到一个问题,就是一个项目中,如果有一部分PHP文件中含了中文字符,比如要echo出一些文本到页面,然后另一个PHP文件中也包含了中文,但这个文件是UTF-8编码的,在输出的时候按前面各位讲的方法可以控制,但是用IDE编辑代码的时候就比较痛苦,比如NetBeans,要指定一个项目的编码格式,如果指定为ANSI,那UTF8那些页面编辑时就显示乱码,如果指定为UTF8那么有ANSI编码的那些文件编辑时就显示为乱码,所以很不方便.今天又试了一下VS.PHP,还没确认是否可能规避这个问题.
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP: A Key Language for Web DevelopmentPHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function