PHP:在斯普利特的字符串数组的foreach CHAR [英] PHP: Split a string in to an array foreach char
问题描述
让您的密码至少需要资金,并仔细的一个符号或数字我想提出一个方法。
我想分裂字符串失去字符,然后使用preggmatch来算,如果它包含一个资本和符号/数字。
I am making a method so your password needs at least one captial and one symbol or number. I was thinking of splitting the string in to lose chars and then use preggmatch to count if it contains one capital and symbol/number.
不过,我的确在动作脚本这样的事情,但无法弄清楚这是怎么叫的PHP。我不能找到一种方法,把每个词的一个字符数组中
however i did something like this in action script but can't figure out how this is called in php. i cant find a way to put every char of a word in a array.
AS3例如
for(var i:uint = 0; i < thisWordCode.length -1 ; i++)
{
thisWordCodeVerdeeld[i] = thisWordCode.charAt(i);
//trace (thisWordCodeVerdeeld[i]);
}
谢谢,
Matthy
Thanks, Matthy
推荐答案
您可以访问字符的字符串以同样的方式,你会访问数组的索引,例如
You can access characters in strings in the same way as you would access an array index, e.g.
$length = strlen($string);
$thisWordCodeVerdeeld = array();
for ($i=0; $i<$length; $i++) {
$thisWordCodeVerdeeld[$i] = $string[$i];
}
你也可以这样做:
You could also do:
$thisWordCodeVerdeeld = str_split($string);
然而,你可能会发现更容易验证字符串作为整个字符串,例如使用常规的前pressions。
However you might find it is easier to validate the string as a whole string, e.g. using regular expressions.
这篇关于PHP:在斯普利特的字符串数组的foreach CHAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!