Thinkphp Framework String Class explanation

Source: Internet
Author: User
A string will be encountered in the development of thinkphp, and this article will explain its related knowledge.

In the PHP development site, the use of the thinkphp framework can greatly improve our development efficiency, thinkphp framework not only the entire website skeleton has been structured, but also provides a very rich class library. The following is mainly about the string class that we use most in the thinkphp framework.

1. Generate UUID and GUID

UUID (); #{a67a8215-d4c0-e6e6-2dcb-9d6d180d8056}keygen (); #3a08fd59e58d4fce424659f12d5868d4

2. Check if the character is UTF8 encoded

IsUtf8 ($STR); #bool (True)

3, string interception, support for Chinese and other encodings, the default starting from 0 in the UTF-8 character set interception, and the last display ellipsis

Msubstr ($str, $start =0, $length, $charset = "Utf-8″, $suffix =true) $str: string to intercept $start=0: Start position, default starting from 0 $length: Intercept length $ charset= "Utf-8″: Character encoding, default utf-8$suffix=true: Whether the ellipsis is displayed after the truncated character, the default true is displayed, False is not displayed

4. Generate random strings of a certain length, default length 6 letters, numbers and Chinese mix, can be used to automatically generate passwords or verification code

Randstring ($len =6, $type = ", $addChars =") $len: Length, default 6-bit $type: String type, 0 letters, 1 digits, 2 uppercase letters or uppercase letters plus custom characters, 3 lowercase or lowercase letters with custom characters, 4 Chinese or Chinese plus custom characters $addchars: Extra characters

5. Generate a certain number of equal-length random numbers, and do not repeat

Buildcountrand ($number, $length =4, $mode =1) $number: quantity $len: Length, default 4-bit $type: String type, 0-letter, 1-digit, 2 capital letter or uppercase plus custom character, 3 lowercase or lowercase letters plus custom characters, 4 Chinese or Chinese plus custom characters

6, generate a random character, support batch generation

Buildformatrand ($format, $number =1) $format: Character format, #表示数字, * denotes letters and numbers, $ denotes letter #: number, default one

7, to obtain a certain range of equal-length random numbers, the number of bits is not 0, the length of the maximum value of the length

Randnumber ($min, $max) $min: Minimum $max: Maximum

8, the automatic conversion character set supports array conversion, the default is GBK turn Utf-8

Autocharset ($string, $from = ' GBK ', $to = ' utf-8′) $string: string $from: Character Set, default ' GBK ', $to: Character set, default: ' utf-8′

Before using these string class methods in the thinkphp controller, you need to first introduce ($string = new \org\util\string in ThinkPHP3.2). If you want to use it in a page, you must copy these functions to the public library common.php.

This article detailed the relevant knowledge of string, more relevant knowledge, please pay attention to the PHP Chinese web.

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.