Recommended manual:php complete self-study manual
* 1.str_split($str,$length=1), according to the number of characters, Split the string into an array, the default is 1
* 2.explode($delimiter,$str,$num): Split the string into an array according to the delimiter, the number of array elements can be specified
* 3.implode($glue, $str): Assemble the one-dimensional array into a string according to the delimiter, separated by spaces by default
echo '<pre class="brush:php;toolbar:false">'; $str = 'html,css,jquery,php,mysql,thinkphp'; echo '<p>原始字符串:'.$str.'</p>';
1.str_split($str,$length=1) Split the string into an array according to the number of characters, the default is 1
print_r(str_split($str)); //默认一个字符转为数组中的一个元素 print_r(str_split($str,5)); //5个一组进行转换
2.explode($delimiter,$str,$num): Split the string into an array according to the delimiter, you can Specify the number of array elements
print_r(explode(',',$str)); //用','号进行分割字符串 print_r(explode(',',$str,5)); //指定数组必须是5个元素,最后一个元素保存全部剩余数据
3.implode($glue, $str): Assemble the one-dimensional array into a string according to the delimiter, separated by spaces by default
$arr2 = explode(',', $str); echo implode(' ', $arr2), '<br>'; //用空格分隔 echo implode(',',$arr2), '<br>'; //用,分隔 echo implode('--',$arr2), '<br>'; //用--分隔
Recommended related articles:
1.Convert PHP arrays and strings to each other
2.Detailed explanation of the two methods of converting PHP arrays to strings [Video attached]
3.Explanation of PHP string to array and array to string functions
Related video recommendations:
1.Dugu Jiujian (4)_PHP video tutorial