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
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
