^号表示从第一个开始匹配如:/^\s/
你可以过滤空白,没有必要验证空白。没有实质意义。
正则方法:echo preg_match('/^\s+/', $string);PHP方法:echo strlen($string) > strlen(ltrim($string)) ? 1:0;