Strlen, Ord, substr functions--get length, ASCII, and partial strings

Source: Internet
Author: User

strlen function

Syntax: strlen (String)

Definition and Usage: the strlen () function returns the length of a string.

substr function

Syntax: substr (string,start,length)

Definition and Usage: the substr () function returns part of a string.

Parameter description

    • String: Required. A string that specifies the part to return.
    • Start: Required. Specifies where to start the string. Positive number, starting at the specified position of the string, negative, starting at the specified position from the end of the string, 0, starting at the first character in the string.
    • Charlist: Optional. Specifies the length of the string to return. The default is until the end of the string. A positive number, returned from the position of the start parameter, and a negative number, returned from the end of the string.

Ord function

Syntax: Ord (String)

Definition and Usage: the Ord () function returns the ASCII value of the first character of a string.

Custom SUBSTR_CN function (can intercept Chinese and English mixed string is not messy) "original"

functionSUBSTR_CN ($str _CN,$length){    if(strlen($str _CN) >$length)    {        if(Ord($str _CN[$length]) > 128)$length++; $str _CN=substr($str _CN, 0,$length); }    return $str _CN;}

Syntax: SUBSTR_CN (string,length)

Definition and Usage: the SUBSTR_CN () function returns a portion of the first character of the string, which is not garbled when it intercepts mixed strings in English and Chinese character.

Parameter description

    • String: Required. A string that specifies the part to return.
    • Charlist: Must. Specifies the length of the string to return, and returns all characters if the specified length is exceeded.

Strlen, Ord, substr functions--get length, ASCII, and partial strings

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.