用strlen检查字符串长度

时间:2013-12-17 08:52:56

标签: php strlen

我有这个代码,我希望它检查长度是否 32或40.下面的代码只检查单词的长度是32还是40。

<?
$name = mysql_real_escape_string($_POST['dgt']);
$len = strlen($name);
if (!($len == "32" or $len == "40")){
print "This is not a name.";
} else {
echo 'This is a name';
?>

3 个答案:

答案 0 :(得分:4)

if ($len != 32 && $len != 40)

尝试出来

答案 1 :(得分:0)

怎么样?
if($len != 32 and $len != 40)

答案 2 :(得分:0)

<?php
$name = mysql_real_escape_string($_POST['dgt']);
$len = strlen($name);
if ($len != 32 && $len != 40){
print "This is not a name.";
} else {
echo 'This is a name';
?>