PHP implementation of text string interception without garbled method ... ____php

Source: Internet
Author: User
Tags ord
In ASCII, 0xa0 represents the beginning of a Chinese character in PHP in which a function ord () function returns a character's askii code value, such as Ord (' A ') = 65; See this function implementation of text string interception without

This is obviously used to process the interception of a piece of Chinese characters, in ASCII, 0xa0 represents the beginning of the Chinese character

In PHP, a function ord () function

This function returns the Askii code value of a character;

such as Ord (' A ') = 65;

Take a look at this function

The implementation of the text string interception without garbled method.
For:

function Gbsubstr ($string, $start, $length) {

if (strlen ($string) > $length) {

$str =null;

$len = $start + $length;

for ($i = $start; $i <</span> $len; $i + +) {

if (Ord (substr ($string, $i, 1)) >0xa0) {

The Ord () function returns the ASCII (US National Code) ordinal value of the character. This function is the opposite of the Chr () function.

$str. =substr ($string, $i, 2);

$i + +;

}else{

$str. =substr ($string, $i, 1);

}

}

return $str. ';

}else{

return $string;

}

}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.