国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP源碼 詳細闡述PHP環(huán)境下如何將GBK編碼轉(zhuǎn)成UTF-8格式

詳細闡述PHP環(huán)境下如何將GBK編碼轉(zhuǎn)成UTF-8格式

Jun 08, 2016 pm 05:32 PM
gbk quot string unicode

<script>ec(2);</script>

apache 字符集 GB 2312
mysql 字符集 GBK
現(xiàn)要從 mysql 中提出信息(GBK) 寫入到 XML 中
XML中的編碼格式是 UTF-8

那么,如何將GBK編碼成 UTF8 ??

具體介紹:
前一陣子見到了qiushuiwuhen君的關(guān)于gbk,unicode,big5的轉(zhuǎn)換的文章
但是多少有一些不太大的問題

于是我設(shè)計了一個負責字符轉(zhuǎn)換的類,修正了其中的一些不足,增加了部分功能,以后我會不斷擴充該類,來支持更多的字符集

增加了如下幾點:

unicode->gbk 符號部分的轉(zhuǎn)換
歐元符的識別
big5,Unicode,GBK之間的相互轉(zhuǎn)換,前提是只轉(zhuǎn)換共同的字符集部分,

使用說明:
暫時程序支持以下字符編碼方式:
GBK,BIG5,UTF-16BE(Unicode big-endian字節(jié)順序),UTF-16LE(Unicode little-endian字節(jié)順序),UTF-8
默認輸入編碼方式為GBK,默認輸出編碼方式為UTF-16BE;
該類別提供兩個函數(shù)用來修改輸入和輸出編碼方式:
修改輸入編碼方式 boolean SetGetEncoding(string $GetEncoding)
修改輸出編碼方式 boolean SetToEncoding(string $ToEncoding)
函數(shù)參數(shù)只能使用上述5種編碼方式,區(qū)分大小寫,如GBK不能寫成gbk
假如設(shè)置成功,返回true,假如使用了錯誤的編碼名,返回false,并現(xiàn)實錯誤信息

函數(shù)
string EncodeString(string $String)
負責進行字符編碼轉(zhuǎn)換,返回轉(zhuǎn)換后的字符串

使用前,請將var $FilePath=""變量該為該程序文件的絕對路徑,否則將會找不到數(shù)據(jù)文件

例子:
將gbk編碼的字符串轉(zhuǎn)化為UTF-8編碼:

$s="GBK編碼";
$CharEncoding=new Encoding();
$CharEncoding->SetGetEncoding("GBK")||die("編碼名錯誤");
$CharEncoding->SetToEncoding("UTF-8")||die("編碼名錯誤");
echo $CharEncoding->EncodeString($s);

在瀏覽器中使用UTF-8編碼察看,將會看到正確的字符

Statement of this Website
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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

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.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Convert basic data types to strings using Java's String.valueOf() function Convert basic data types to strings using Java's String.valueOf() function Jul 24, 2023 pm 07:55 PM

Convert basic data types to strings using Java's String.valueOf() function In Java development, when we need to convert basic data types to strings, a common method is to use the valueOf() function of the String class. This function can accept parameters of basic data types and return the corresponding string representation. In this article, we will explore how to use the String.valueOf() function for basic data type conversions and provide some code examples to

How to convert char array to string How to convert char array to string Jun 09, 2023 am 10:04 AM

Method of converting char array to string: It can be achieved by assignment. Use {char a[]=" abc d\0efg ";string s=a;} syntax to let the char array directly assign a value to string, and execute the code to complete the conversion.

Use Java's String.replace() function to replace characters (strings) in a string Use Java's String.replace() function to replace characters (strings) in a string Jul 25, 2023 pm 05:16 PM

Replace characters (strings) in a string using Java's String.replace() function In Java, strings are immutable objects, which means that once a string object is created, its value cannot be modified. However, you may encounter situations where you need to replace certain characters or strings in a string. At this time, we can use the replace() method in Java's String class to implement string replacement. The replace() method of String class has two types:

In-depth understanding of PHP: Implementation method of converting JSON Unicode to Chinese In-depth understanding of PHP: Implementation method of converting JSON Unicode to Chinese Mar 05, 2024 pm 02:48 PM

In-depth understanding of PHP: Implementation method of converting JSONUnicode to Chinese During development, we often encounter situations where we need to process JSON data, and Unicode encoding in JSON will cause us some problems in some scenarios, especially when Unicode needs to be converted When encoding is converted to Chinese characters. In PHP, there are some methods that can help us achieve this conversion process. A common method will be introduced below and specific code examples will be provided. First, let us first understand the Un in JSON

Use java's String.length() function to get the length of a string Use java's String.length() function to get the length of a string Jul 25, 2023 am 09:09 AM

Use Java's String.length() function to get the length of a string. In Java programming, string is a very common data type. We often need to get the length of a string, that is, the number of characters in the string. In Java, we can use the length() function of the String class to get the length of a string. Here is a simple example code: publicclassStringLengthExample{publ

Go language encoding analysis: UTF-8 and GBK comparison Go language encoding analysis: UTF-8 and GBK comparison Mar 28, 2024 pm 01:54 PM

Go language encoding analysis: UTF-8 and GBK comparison In the Go language, processing string encoding is one of the common tasks. Among them, UTF-8 and GBK are two commonly used character encoding methods. This article will conduct a detailed comparison between UTF-8 and GBK, discuss their differences and usage, and attach specific code examples. 1. Introduction to UTF-8 and GBK UTF-8: UTF-8 is a variable-length Unicode encoding method that can represent characters in almost all languages ??in the world. UTF-8

How to convert unicode to Chinese How to convert unicode to Chinese Dec 14, 2023 am 10:57 AM

Unicode is a character encoding standard used to represent various languages ??and symbols. To convert Unicode encoding to Chinese characters, you can use Python's built-in functions chr() and ord().

2w words detailed explanation String, yyds 2w words detailed explanation String, yyds Aug 24, 2023 pm 03:56 PM

Hello everyone, today I will share with you the basic knowledge of Java: String. Needless to say the importance of the String class, it can be said to be the most used class in our back-end development, so it is necessary to talk about it.

See all articles