Ayrıca Bakınız

User Contributed Notes 5 notes

useful for finding beginning of quotes and/or tags in a variable containing html. $pos = strcspn($data, '<"\''); will find the first occurance of either the beginning of a tag, or a double- or single-quoted string.

When you use the third parameter remember that the function will return the number of characters it bypassed, which will *not* be the position in your source string. It's a simple fix to just add your third parameter value to the function result to get the position in the first string where the scan stopped, but I didn't think of it at first.

strcspn() can also be thought of as analogous to the following regular expression:<?php// where ... represents the mask of characterspreg_match('/[^ ...]/', substr($subject, $start, $length) );?>By this analogy, strcspn() can be used in place of some regular expressions to match a pattern without the overhead of a regex engine -- for example, ways to verify if an input string represents a binary value:<?phppreg_match('/^[01]+$/i', $subject);// or...!preg_match('/[^01]/i', $subject);