文字列に複数のパターンを許可したくない、たとえば、
$string = "php in stackoverflow"; // multiple spaces not allowed
$string = "php in--stackoverflow"; // multiple hyphens not allowed
$string = "php in__stackoverflow"; // multiple underscores not allowed
etc
したがって、これらの行で機能します。
if(preg_match('/\s\s+/', $string)) echo "only a single spaces are allowed";
if(preg_match('/\-\-+/', $string)) echo "only a single hyphens are allowed";
if(preg_match('/\_\_+/', $string)) echo "only a single underscores are allowed";
また、以下の組み合わせパターンを許可したくないので、上の行は機能しません。
$string = "php in -stackoverflow"; // a space with a hyphen not allowed
$string = "php in-_stackoverflow"; // a hyphens with a underscore not allowed
$string = "php in_ stackoverflow"; // a underscore with a space not allowed
etc
簡単なスクリプトでこれを達成できるアイデアはありますか?