Home >Backend Development >PHP Tutorial >Detailed introduction on how to write this regular expression to split strings
How to write this regular expression to split a string
<pre class="brush:php;toolbar:false"> php > $x="xy\nw"; php > echo strlen($x);4
How to split it into an array of four characters?
str_split
Come on ajs
'xynw'.match(/(.{1})/g)
<?php $str = 'xynw'; $chars = preg_split('//', $str, -1,PREG_SPLIT_NO_EMPTY); print_r($chars);?>
If you directly want to get a certain character, the string can be accessed directly using an array-like method. If you have other reasons to convert to an array, just ignore me. answer.