PHP/String/strcspn

Материал из Web эксперт
Перейти к: навигация, поиск

See what portion of a string is composed only of a given set of characters

   <source lang="html4strict">

<? $twister = "Peter Piper picked a peck of pickled peppers"; $charset = "Peter picked a"; print("The segment matching "$charset" is " . strspn($twister, $charset) . " characters long"); ?>

      </source>
   
  


strcspn($password, "1234567890")

   <source lang="html4strict">

<?php

  $password = "a12345";
  if (strcspn($password, "1234567890") == 0) {
     print "Password cannot consist solely of numbers! ";
  }

?>

      </source>
   
  


strspn: Find length of initial segment matching mask

   <source lang="html4strict">

<?php

  $password = "3312345";
  if (strspn($password, "1234567890") == strlen($password))
     echo "The password cannot consist solely of numbers!";

?>


      </source>