PHP character processing functions str_split, implode, strpos, substr, and strlen usage Summary

Source: Internet
Author: User

 

PHP is often used to process string characters. php's built-in character functions provide very powerful functions that can basically complete most character processing operations, for example, use the str_split function to convert a character into an array, the implode function converts an array into one character, the strpos function searches for another character in one character, and the substr function obtains a certain number of characters in the character. the strlen function obtains the character length. These are the most basic knowledge of PHP, which is easy to use in daily work. I have summarized this function for your reference only.

1. How to convert a character into an array
Solution:Str_split ()Function
Example:
$ Biuuu = 'www .biuuu.com ';
Print_r (Str_split($ Biuuu ))
Output result:
Array
(
[0] => B
[1] => I
[2] => U
[3] => U
[4] => U
)

2. How to convert an array into a character
Solution:Implode() Function
Example:
$ Biuuu = array ('B', 'I', 'U ');
Print_r (Implode('', $ Biuuu ));
Output result
Biiuu

3. How to find another character in one character
Solution:StrposOr strstr
Example:
$ Biuuu = 'This is my website biuuu.com ';
$ Search = 'biuuu ';
Print_r (Strpos($ Biuuu, $ search ));
Output result:
19

4. How to obtain a certain number of characters
Solution:Substr() Function
Example:
$ Biuuu = 'This is my website biuuu.com ';
Print_r (Substr($ Biuuu, 19 ));
Output result:
Biuuu.com

5. How to get the character Length
Solution:Strlen() Function
Example:
$ Biuuu = 'This is my website biuuu.com ';
Print_r (Strlen($ Biuuu ));
Output result
28

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.