PHP array to string

Source: Internet
Author: User
Tags array to string

With the development of the times, our development technology is also updated, and PHP is still quite common. So I have studied PHP array conversion to string, and I will share it with you here, I hope it will be useful to you.

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, the str_split function is used to convert a character into an array, the implode function converts the php array to a string, the strpos function searches for another character in one character, the substr function obtains a certain number of characters in the character, strlen function to obtain the length of characters and so on. 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:

 
 
  1. $biuuu = 'www.biuuu.com';  
  2. print_r(str_split($biuuu))  

Output result:

 
 
  1. Array  
  2. (  
  3. [0] => b  
  4. [1] => i  
  5. [2] => u  
  6. [3] => u  
  7. [4] => u  

2. How to convert a php array to a string
Solution: implode () function
Example:

 
 
  1. $biuuu = array('b','i','u','u','u');  
  2. print_r(implode('',$biuuu)); 

Output result biiuu

3. How to find another character in one character
Solution: strpos or strstr
Example:

 
 
  1. $biuuu = 'this is my website biuuu.com';  
  2. $search = 'biuuu';  
  3. print_r(strpos($biuuu,$search)); 

Output result: 19

4. How to obtain a certain number of characters
Solution: substr () function
Example:

 
 
  1. $biuuu = 'this is my website biuuu.com';  
  2. print_r(substr($biuuu,19)); 

Output result: biuuu.com

5. How to get the character Length
Solution: strlen () function
Example:

 
 
  1. $biuuu = 'this is my website biuuu.com';  
  2. print_r(strlen($biuuu)); 

Output result 28

The above PHP character processing functions str_split, implode, strpos, substr, and strlen are frequently used in actual development. I hope they will be helpful to you.


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.