Learning PHP notes-substr (), explode (), strrev ()

Source: Internet
Author: User

Substr (STR, start, length );

Example: substr ('php is very good language );

Output is ve;

If the length of Start> STR is returned ();

Substr ('php is very good language );

Substr ('php is very good language ',4);

Output as (blank)

Output is V (It indicates that both start and langth are 4)

When start is a negative value, it starts to read from the end of STR (* at this time, it starts to read from-1 rather than from 0 ),

Substr ('php is very good language );

Output as uage

When the value of length is negative, Length indicates reading from the end and intercepting the end position of Str.

Substr ('php is very good language ', 4,-5 );

Output is very good LAN

Explode () Splits function strings into arrays;

// Example 1
$ Pizza = "piece1 piece2 piece3 piece4 piece5 piece6 ";
$ Pieces = explode ("", $ pizza );
Echo $ pieces [0]; // piece1
Echo $ pieces [1]; // piece2

// Example 2
$ DATA = "foo: *: 1023: 1000:/home/FOO:/bin/sh ";
List ($ user, $ pass, $ uid, $ GID, $ GECOS, $ home, $ shell) = explode (":", $ data );
Echo $ GECOS. "<br>"; // foo
Echo $ shell ;//*

Strrev () outputs the string from the back to the front

Echo strrev ("June"); // outputs "enuj"

Setlocalhost(Content location) to set the local environment. Content, specify the scenario information constants to be set (

    • Lc_all-constants of all subordinates
    • Lc_collate-sort order
    • Lc_ctype-character classification and conversion (for example, converting all characters into lowercase or upper case)
    • Lc_messages-System Information Format
    • Lc_monetary-currency/currency format
    • Lc_numeric-numeric format
    • Lc_time-Date and Time Format

); Location, set the country region, for example, chs.

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.