在空字符串上爆炸返回数组计数为1 [关闭]

explode on empty string returns array count as 1.

   $consName =explode("|",$docDet['doc_cons_filename']); 
   count($consName);

If there is some value in $docDet['doc_cons_filename'] like ab|cd|de then count($consName) returns 3.

But its returning 1 if $docDet['doc_cons_filename'] has empty value.

is it possible to return count as 0 if we perform count(explode("|",$docDet['doc_cons_filename'])) where $docDet['doc_cons_filename'] = ""

Can anyone help me with solution?

$arr = array();
$str = "yes you are!";
if($i = substr_count($str,"|"))
  $arr = explode("|", $str, $i+1);
echo count($arr);

The solution would be to count explicitly how many times separator is found within your string. See substr_count()