PHP Learning Notes-string practice continuation

Source: Internet
Author: User

1. String Split function str_split ($str, length), $str is the string to be cut, length is the split length, the default is 1 if it is a negative number, false

1 $str= ' helloworld! ' ; 2 Print_r (str_split($str, 2)); 3 Echo ' <br> '; 4 Print_r (str_split($str));

Output Result:

Array ([0] = He [1] = ll [2] = = ow [3] = or [4] = ld [5] = =!)
Array ([0] = h [1] = e [2] = + [3] = l [4] = = O [5] = w [6] = o [7] = R [8] = l [9] =& Gt d [Ten] =! )

2. String reversal function Strrev ($STR), returns the string in reverse

$str= ' Hello World '; Echo Strrev ($str);

Output Result: Dlrow Olleh

3.chunk_split ($str, length, $s), divides str into substrings of length lengths and adds the string s later, and finally joins to return the new string

$str= ' language '; Echo Chunk_split ($str, 2, ', ');

Output Result: La,ng,ua,ge,

4. Remove the left character function LTrim ($str, $s)and remove $s from the left side of $str

$str= ' HelloWorld '; $s= ' hello '; Echo LTrim ($str,$s);

Output: World

5. String converted to uppercase function Strtoupper ($STR) and converted to lowercase function strtolower ($str)

$str= ' Hello World '; $str 1=strtoupper($str); Echo $str 1, ' <br> '; $str 2=strtolower($str 1); Echo $str 2;

Output Result:

HELLO World
Hello World

PHP Learning Notes-string practice continuation

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.