如何在php程序中检测字符串上的空格

时间:2012-11-17 17:25:59

标签: php string whitespace detect

我想对两个字符串进行治疗,我必须知道是否有空格来阻止我的治疗并转移到其余的字符 我测试了它,但它不能解决问题:

 for ($i = 0; $i < $lenght; $i++) {

                    if($text[$i] <> '' && $mask[$i] <> ''){

                        $nbrcrypted = $stringtonumber[$text[$i]] + $stringtonumber[$mask[$i]];
                        $resultat .= $numbertostring[$nbrcrypted];
                    }else{

                        $indice = false;
                    }                    
                }

我怎样才能实现这一目标,提前谢谢

2 个答案:

答案 0 :(得分:2)

if($text[$i] <> '' && $mask[$i] <> ''){没用,请使用if($text[$i] !== ' ' && $mask[$i] !== ' '){作为空格

答案 1 :(得分:1)

我不知道你实际想要做什么,但如果你想测试你的字符串是否有空格:

if ( strpos( $yourString, ' ' ) !== false )
    null; // string has whitespace(s)