Rumah  >  Artikel  >  pembangunan bahagian belakang  >  php怎么设置gbk编码?

php怎么设置gbk编码?

青灯夜游
青灯夜游asal
2020-08-25 10:59:254005semak imbas

php设置gbk编码的方法:在PHP文件的头部,添加“header("Content-type: text/html; charset=gb2312");”代码来声明content-type,定义网页的编码为gbk编码,然后保存即可。

php怎么设置gbk编码?

推荐:《PHP视频教程

php设置gbk编码

如果欲使用gbk编码,那么php要输出头:header(“Content-Type: text/html; charset=gb2312"),静态页面添加275c0a3d0eca89fa26849bad3f20c07b,所有文件的编码格式为ANSI,可用记事本打开,另存为选择编码为ANSI,覆盖源文件。

如果欲使用utf-8编码,那么php要输出头 :header(“Content-Type: text/html; charset=utf-8"),静态页面添加f7cc7cb3585ee1b04726d7fb499fdd83,所有文件的编码格式为utf-8。

header()声明content-type

header(“Content-Type: text/html; charset=gb2312")

Content-Type(内容类型),一般是指网页中存在的 Content-Type,用于定义网络文件的类型和网页的编码,决定浏览器将以什么形式、什么编码读取这个文件,这就是经常看到一些 PHP 网页点击的结果却是下载一个文件或一张图片的原因。

Content-Type 标头告诉客户端实际返回的内容的内容类型。

语法格式:

Content-Type: text/html; charset=utf-8
Content-Type: multipart/form-data; boundary=something

实例:

常见的媒体格式类型如下:

  • text/html : HTML格式

  • text/plain :纯文本格式

  • text/xml : XML格式

  • image/gif :gif图片格式

  • image/jpeg :jpg图片格式

  • image/png:png图片格式

以application开头的媒体格式类型:

  • application/xhtml+xml :XHTML格式

  • application/xml: XML数据格式

  • application/atom+xml :Atom XML聚合格式

  • application/json: JSON数据格式

  • application/pdf:pdf格式

  • application/msword : Word文档格式

  • application/octet-stream : 二进制流数据(如常见的文件下载)

  • application/x-www-form-urlencoded : f0992a6511573584ab2f3cd699752638中默认的encType,form表单数据被编码为key/value格式发送到服务器(表单默认的提交数据的格式)

另外一种常见的媒体格式是上传文件之时使用的:

  • multipart/form-data : 需要在表单中进行文件上传时,就需要使用该格式

相关学习推荐:PHP编程从入门到精通

Atas ialah kandungan terperinci php怎么设置gbk编码?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya:php如何开启错误报告Artikel seterusnya:php如何计算日期差几天