PHP Learning Series (1)--String processing function (2)

Source: Internet
Author: User

6. The Chunk_split () function divides the string into a series of smaller parts. This function does not change the original string.

Syntax: Chunk_split (string,length,end)

Parameters:

string--required. Specifies the string to be split.

length--is optional. A number that defines the length of the string block.

end--is optional. A string value that defines what is placed after each string block.

Example 1

This example separates each character and adds "." :

<? PHP $str = "Hello world!" ; Echo Chunk_split ($str, 1, "." );? >

Output:

H.E.L.L.O. w.o.r.l.d.!.
Example 2

This example splits a string after six characters and adds "...":

<? PHP $str = "Hello world!" ; Echo Chunk_split ($str, 6, "...");? >

Output:

Hello ... world!...
7. The convert_cyr_string () function converts a character from one Cyrillic character to another.

The supported Cyrillic character sets are:

    • K-koi8-r
    • w-windows-1251
    • I-iso8859-5
    • a-x-cp866
    • d-x-cp866
    • M-x-mac-cyrillic
Grammar
Convert_cyr_string (String,from,to)
8. The Convert_uudecode () function decodes a uuencode encoded string.
Syntax: Convert_uudecode (String) example

In this example, we will decode the UUENCODE encoded string by using Convert_uudecode ():

<? PHP $str = ", 2&5l;&\@=v]r;&0a '"; Echo Convert_uudecode ($str);? >

Output:

Hello world!
9. The Convert_uuencode () function encodes a string using the uuencode algorithm.
Syntax: Convert_uuencode (String)

Attention:

This function converts all strings (including binary) to printable strings, ensuring the security of their network transmissions. The string of uuencode is approximately 35% larger than the original string.

Example

In this example, we will encode the string using Convert_uuencode ():

<? PHP $str = "Hello world!" ; Echo Convert_uuencode ($str);? >

Output:

, 2&5l;&\@=v]r;&0a '

10. The Count_chars () function returns information about the characters used in the string.

Grammar
Count_chars (string,mode)

Parameters
Describe

String
Necessary. Specifies the string to check.

Mode

Optional. Specifies the return mode. The default is 0. There are the following different return modes:

    • 0-Array, ASCII value is the key name, the number of occurrences is the key value
    • 1-Array, ASCII value is the key name, the number of occurrences is a key value, only the number of occurrences greater than 0 is listed
    • 2-Array, ASCII value is the key name, the number of occurrences is a key value, only the number of occurrences equal to 0 is listed
    • 3-string with all the different characters used
    • 4-A string with all the different characters that have not been used
Example 1

In this example, we will use Count_chars () to check the string, with the return mode set to 1:

<? PHP $str = "Hello world!" ; Print_r (count_chars($str, 1));? >

Output:

Array ([+] = 1[33] = 1[72] [1[87] = 1[100] = 1[101] [1[108] = 3[111] and 2[114] + 1)
Example 2

In this example, we will use Count_chars () to check the string, with the return mode set to 3:

<? PHP $str = "Hello world!" ; Echo Count_chars ($str, 3);? >

Output:

! Hwdelor

PHP Learning Series (1)--String processing function (2)

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.