Nov
28
2008

Strings and Patterns: Matching

The PHP 5 Zend Certification exam section Strings and Patterns requires knowledge of Matching. It is presumed that matching isto the use of strspan();

You can use strspan(); to match a strings constrictors against allowed (whitelist) constrictors. The function does not reuturn true or false instead returns the amount of constrictors that match the whitelist like so:

$string = ’133445abcdef’;
$mask =12345’;
echo strspn ($string, $mask); // Outputs 6

Their are third and fourth perimeters that can be passed to the function, this sets out the start and end point like such:

$string = ’1abc234’;
$mask = ’abc’;
echo strspn ($string, $mask, 1, 4);

This will output 3, this is because we skip the first character 1 and continue for up to 4 character. Only the first three character meet the mask, so we output 3.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • LinkedIn
  • Live
  • StumbleUpon
  • Technorati
  • TwitThis
Written by Adam in: 07. Strings and Patterns |

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment

WordPress Powered, Theme by TheBuckmaker.com | Add to Technorati Favorites. | RSS and Comments RSS