In PHP we are going to convert the string in the array can use the function has Str_split (), Explode (), preg_split () function, if the array is converted to a string we also have a function implode () function with directly to the array connected together.
Let's start with a string conversion array.
Str_split ()
Print_r (Str_split ("Hello"));
?>
Array
(
[0] = H
[1] = = E
[2] = l
[3] = L
[4] = O
)
Explode ()
$STR = "Hello World". It ' s a beautiful day. ";
Print_r (Explode ("", $str));
?>
Results
Array
(
[0] = = Hello
[1] = world.
[2] + = It ' s
[3] = a
[4] = Beautiful
[5] = = Day.
)
Preg_split () function
The code is as follows |
Copy Code |
$user _info = "+j+++g+++++w"; $fields = Preg_split ("/+{1,}/", $user _info); while ($x < sizeof ($fields)): Print $fields [$x]. " "; $x + +; Endwhile; ?> |
Summary in PHP str_split (), explode () function is the same, this is not introduced.
Converts an array to a string
Implode ()
Cases
The code is as follows |
Copy Code |
$array = Array (' A ', ' B ', ' C '); echo implode ($array); Results ABC |
http://www.bkjia.com/PHPjc/445612.html www.bkjia.com true http://www.bkjia.com/PHPjc/445612.html techarticle In PHP We are going to convert the string in the array can use the function has Str_split (), Explode (), preg_split () function, if the array is converted to a string we also have a function implode () function ...