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 characters
- Function Substring ($ str, $ max ){
- $ Cnt = 0; // actual count
- $ Index = 0; // Current index
- $ Output = ''; // output
- //
- While ($ cnt <$ max & $ index
- $ Output. = $ str [$ index];
- // Big5
- If (ord ($ str [$ index])> = 0x81 &&
Ord ($ str [$ index]) <= 0xfe ){
- If ($ index + 1
- If (ord ($ str [$ index + 1])> = 0x40
& Ord ($ str [$ index + 1]) <0x7e)
- | (Ord ($ str [$ index + 1])> = 0xa1
& Ord ($ str [$ index + 1]) <= 0xfe )){
- $ Index ++;
- $ Output. = $ str [$ index];
- }
- }
- }
- // Gb2312
- Else if (ord ($ str [$ index])> = 0xa1
& Ord ($ str [$ index]) <= 0xf7 ){
- $ Output. = $ str [$ index];
- If ($ index + 1
- If (ord ($ str [$ index + 1])> = 0xa1
& Ord ($ str [$ index + 1]) <0xfe ){
- $ Index ++;
- $ Output. = $ str [$ index];
- }
- }
- }
- Else {
- }
- $ Cnt ++;
- $ Index ++;
- }
- Return $ output;
- }
The preceding code example shows how to use the PHP Substr library function to intercept Chinese characters.
The PHP Substr library function program below explain is not perfect, but there is no problem in handling general Chinese (GB18030, GB2312, BIG5. This function is not suitable for UTF-8 encoded text. // $ Str character...