') | ASCII (' Simaopig ') |+------------+-------------------+-------------------+| 121 | 83 | 115 |+------------+-------------------+-------------------+1 row in Set (0.00 sec)*/
The ORD () function returns the numeric encoding of the specified character, often used in place of ASCII ():
Well, how I feel. The return value is exactly the same as ASCII (). PHP also has this function, seemingly.
Select Ord
One, the Chinese character to decimal principle analysis
In GBK encoding, a Chinese character is composed of two characters, and the method to get the character string is as follows
Copy Code code as follows:
$string = "Don't be infatuated with brother";
$length = strlen ($string);
for ($i =0; $i if (Ord ($string [$i]) >127) {
$result [] = Ord ($string [$i]). ' '.
-------------------------------------------------- Insert the user's purchase Point Information------------------------------------------------Create procedure insertuseraccount@ Phone nvarchar (15 ),@ Point int,@ Status nvarchar (50 ),@ Step1time datetime,@ Payby nvarchar (100 ),@ ID Int = 0 outputAsSet nocount on
--------------------------------------- Generate a serial number as the document number --------------------------------Declare @ ordid nvarchar (100)Declare @
In the fourth part of the Chinese character encoding Study Series, PHP analyzes the conversion principle of Chinese characters, mainly discusses the methods for converting Chinese characters into decimal and hexadecimal formats, and master the conversion principle for practical development. This article takes GBK encoding as an example to discuss the character conversion principle of GBK encoding.
I. Analysis of conversion principle from Chinese characters to decimal characters
A Chinese chara
It is very hard to find that PHP has always supported the problem of HKSCS which has been difficult for a long time. But not the HK-SCS, The BIG5-HKSCS.
The following is a solution to solve the HK increment character set:
The HTML faces are set as UTF-8,
Before importing data to analyticdb, iconv ('big5-HKSCS ', 'utf8', $ string)
Use the following function if Unicode is required
Function string2unicode ($ data, $ LANGUAGE)
{
$ DATA = nl2br (TRIM ($ data ));
$ DATA = str_replace ('$ STR = '';
Pre
Program code:Program codeUnicode encoded form
Program code:Program codeEncryption program
Program code:Program code$ Text = "http://1v1.name ";Preg_match_all ("/[\ X80-\ xFF]?. /", $ Text, $ AR );Foreach ($ ar [0] as $ V)Echo "". utf8_unicode (iconv ("gb2312", "UTF-8", $ V )).";";?>// Utf8-> UnicodeFunction utf8_unicode ($ c ){Switch (strlen ($ C )){Case 1:Return ord ($ C );Case 2:$ N = (ord ($ C [0]) 0x3
BeginnerThe following PHP Substr library function program is not perfect, but it is no problem to process General Chinese (GB18030, GB2312, BIG5. This function is not suitable for UTF-8 encoded text.
// $ Str string
// $ Max maximum number of characters
Function Substring ($ str, $ max ){
$ Cnt = 0; // actual count
$ Index = 0; // current index
$ Output = ''; // output
//
While ($ cnt
$ Output. = $ str [$ index];
// Big5
If (ord
Function introduction of PHPSubstr Library. The PHPSubstr library function program below is not perfect for beginners, but there is no problem in handling general Chinese (GB18030, GB2312, BIG5. This function is not suitable for UTF-8 encoded text. $ StrThe following PHP Substr library function program is not perfect, but it is no problem to process General Chinese (GB18030, GB2312, BIG5. This function is not suitable for UTF-8 encoded text.
// $ Str string
// $ Max maximum number of ch
Okay? $ Text e-book library; preg_match_all ([x80-xff]?., $ Text, $ ar); foreach (encoding conversion between gb2312 and unicode
The following example converts gb2312 to "full ".
The iconv function after php4.3.1 is very useful, but you only need to write a conversion function from uft8 to unicode.Check the table (gb2312.txt ).
$ Text = "e-book library ";Preg_match_all ("/[\ x80-\ xff]?. /", $ Text, $ ar );Foreach ($ ar [0] as $ v)Echo " #". utf8_unicode (iconv ("GB2312", "UTF-8", $ v )).";";?
In the fourth part of the Chinese character encoding Study Series, PHP analyzes the conversion principle of Chinese characters, mainly discusses the methods for converting Chinese characters into decimal and hexadecimal formats, and master the conversion principle for practical development. This article takes GBK encoding as an example to discuss the character conversion principle of GBK encoding.
I. Analysis of conversion principle from Chinese characters to decimal characters
A Chinese chara
Encoding conversion between gb2312 and unicode the following example converts gb2312 to an encoding conversion between gb2312 and unicode in the form of quot; amp; #20840; quot;
The following example converts gb2312 to "full ".
The iconv function after php4.3.1 is very useful, but you only need to write a conversion function from uft8 to unicode.
Check the table (gb2312.txt ).
The code is as follows:
$ Text = "";Preg_match_all ("/[\ x80-\ xff]?. /", $ Text, $ ar );Foreach ($ ar [0] as $
Php Chinese characters and hexadecimal encoding conversion methods
// Convert Chinese characters to hexadecimal encoding
Function hexencode ($ s ){
Return preg_replace ('/(.) /es ', "str_pad (dechex (ord (' \ 1'), 2, '0', str_pad_left)", $ s );
}
// Convert hexadecimal encoding to Chinese characters
Function hexdecode ($ s ){
Return preg_replace ('/(\ w {2})/E', "chr (hexdec (' \ 1')", $ s
Analysis on the conversion principle of Chinese characters in PHP. I. Analysis of the conversion principle of Chinese characters to decimal characters a Chinese character in GBK encoding is composed of two characters. the method to obtain a Chinese character string is as follows: Copy the code below: $ string should not be infatuated with brother
I. Analysis of conversion principle from Chinese characters to decimal characters
A Chinese character in GBK encoding consists of two characters. the
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.