strspn

int strspn(string string, string mask) 

Finds the length of the initial substring containing only characters from mask.

Returns:

Number of characters found

Description:

strspn() returns the length of the substring at the start of string that contains only characters from mask . Given string abcdef and mask abc, for example, the function returns 3.

Version:

PHP 3.0.3+, PHP 4+

See also:

To return the number of characters present in a string before any of a set of specified characters is found:

strcspn() 

Example:

Display names that start with vowels
<?php 
$list = array ("Andrew", "Brigitte", "Chris", "Deb"); 
foreach ($list as $name) {
   if (strspn ($name, 'aeiouyAEIOUY')) {
      echo $name, "\n"; 
   } 
} 
?> 

Output: 
Andrew 

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.