With the development of the Times, our development technology also with the update, for PHP or more commonly used, so I studied the PHP array to the string, here to take out and share with you, hope to be useful to everyone.
It is often necessary to use PHP to handle characters string,php built-in character functions that provide a very powerful function that basically completes most character processing operations. If you use the Str_split function to convert a character to an array, the IMPLODE function converts the PHP array to a string, the Strpos function looks for another character in one character, the substr function gets a few characters in the character, the strlen function gets the character length, and so on. These are the most basic knowledge of PHP, convenient for daily use, I will do some summary of this function, for reference only.
1, how to convert a character into an array
Workaround: Str_split () function
Examples are as follows:
$bai ='www.baidu.com';
Print_r (Str_split ($bai))
Output Result:
Array
(
[0] = b
[1] = I
[2] = u
[3] = u
[4] = u
)
2, how to turn a PHP array into a string
Workaround: Implode () function
Examples are as follows:
$bai = Array ('b','I','u','u','u');
Print_r (Implode ("', $bai));
Output result Biiuu
3, how to find another character in one character
Workaround: Strpos or Strstr
Examples are as follows:
$bai ='This is my website baidu.com';
$search ='Baidu';
Print_r (Strpos ($bai, $search));
Output Result: +
4, how to get a few characters in a character
Workaround: substr () function
Examples are as follows:
$BIUUU ='This is my website baidu.com';
Print_r (substr ($bai, +));
Output Result: baidu.com
5, how to get the character length
Workaround: strlen () function
Examples are as follows:
$bai ='This is my website baidu.com';
Print_r (strlen ($bai));
Output Results 28
The above several PHP character processing functions str_split, implode, Strpos, substr and strlen in the actual development because often need to use, hope to be helpful to everybody.
Detailed introduction to PHP array to string