I got a question when I was doing some Array in PHP.
I don’t know how to write the code for the following case:
$arrs = array("a@c", "cr", "exd", "hello", "gg%j", "hwa", "@", "8");
foreach ($arrs as $arr){
// if $arr does not belong to any characters from a to z,
// then there must be some special character in it.
// Say for example, "a@c" will still be regarded as fine string,
// since it contains normal characters a and c.
// another example, "gg%j" will also be fine, since it contains g and j.
}
You could use a regex, and the [
preg_match][1] function :Which would get you the following output :
Here, the regex is matching :
^aandz:[a-z]*$So, if the string contains anything that’s not between
aandz, it will not match ; andvar_dumpthe string.[1]: https://www.php.net/preg_match