2012-11-17 29 views
0

我想对两个字符串进行处理,并且必须知道是否有空格来停止我的处理并转移到字符的其余部分 我测试了它,但它没有“T统治问题:如何在php程序中检测字符串上的空白

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

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

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

         $indice = false; 
        }      
       } 

我怎么能做到这一点,谢谢你提前

+1

定义“空白”。你只是指空间吗?水平制表符?回车?换行? – rdlowrey

回答

2

if($text[$i] <> '' && $mask[$i] <> ''){是没用的,使用if($text[$i] !== ' ' && $mask[$i] !== ' '){的空间

+0

你是对的,我没注意 – user201892

1

我不明白你实际上试图做,但如果你想测试你的字符串空白:

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