如何通过IF(COUNT())修复charectors的长度

时间:2016-04-06 07:08:55

标签: php

我的代码无效:在COMMENTS框中计算值是否正确?

//function to count the entered text in COMMENTS section

function isEligible($comments)
{
  if(count($comments <12 && $comments > 40))
  {
    print "Plz enter the value between 12_40";
    return false;

  }

return true;
}

1 个答案:

答案 0 :(得分:0)

count()用于数组,所以正确的语法应该是:

<?php
    //function to count the entered text in COMMENTS section
    function isEligible($comments) {
        if (strlen($comments) < 12 || strlen($comments) > 40) {
            print "Plz enter the value between 12 and 40 characters";
            return false;
        }
        return true;
    }
?> 

假设$comments是字符串。