PHP intercept Chinese string-ord () function 0xa0 ...

Source: Internet
Author: User
Tags ord

In ASCII, 0xa0 represents the beginning of a Chinese character where a function in PHP, the Ord () function, returns the Askii code value of a character, such as Ord (' A ') = 65;

<?php

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

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

$str=null;

$len=$start+$length;

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

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

the//ord () function returns the ASCII (U.S. National Standard Interchange 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;

}

}

echo gbsubstr ("My 1234 name is Showan ",0,8);

?>

PHP intercept Chinese string-ord () function 0xa0 ...

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.