PHP: Split a string in to an array foreach char(PHP:将字符串拆分为数组 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]);
}
谢谢,马蒂
推荐答案
您可以像访问数组索引一样访问字符串中的字符,例如
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];
}
你也可以这样做:
$thisWordCodeVerdeeld = str_split($string);
但是您可能会发现将字符串作为一个完整的字符串进行验证更容易,例如使用正则表达式.
However you might find it is easier to validate the string as a whole string, e.g. using regular expressions.
这篇关于PHP:将字符串拆分为数组 foreach char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP:将字符串拆分为数组 foreach char


基础教程推荐
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php中的foreach复选框POST 2021-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- php中的PDF导出 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- Web 服务器如何处理请求? 2021-01-01