From 5fb277d606b080ae0a481201386c6a574d64f775 Mon Sep 17 00:00:00 2001 From: Christoph Michael Becker Date: Sat, 15 Aug 2015 14:43:21 +0000 Subject: [PATCH] improve strspn/strcspn documentation (contributed by francois) git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@337482 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/strings/functions/strcspn.xml | 87 ++++++++++++++++++++----- reference/strings/functions/strspn.xml | 7 ++ 2 files changed, 77 insertions(+), 17 deletions(-) diff --git a/reference/strings/functions/strcspn.xml b/reference/strings/functions/strcspn.xml index 2037391b12..3176526403 100644 --- a/reference/strings/functions/strcspn.xml +++ b/reference/strings/functions/strcspn.xml @@ -10,35 +10,43 @@ &reftitle.description; intstrcspn - stringstr1 - stringstr2 + stringsubject + stringmask intstart intlength Returns the length of the initial segment of - str1 which does not - contain any of the characters in str2. + subject which does not + contain any of the characters in mask. + + + If start and length + are omitted, then all of subject will be + examined. If they are included, then the effect will be the same as + calling strcspn(substr($subject, $start, $length), + $mask) (see + for more information). - + &reftitle.parameters; - str1 + subject - The first string. + The string to examine. - str2 + mask - The second string. + The string containing every disallowed character. @@ -46,7 +54,25 @@ start - The start position of the string to examine. + The position in subject to + start searching. + + + If start is given and is non-negative, + then strcspn will begin + examining subject at + the start'th position. For instance, in + the string 'abcdef', the character at + position 0 is 'a', the + character at position 2 is + 'c', and so forth. + + + If start is given and is negative, + then strspn will begin + examining subject at + the start'th position from the end + of subject. @@ -54,21 +80,42 @@ length - The length of the string to examine. + The length of the segment from subject + to examine. + + + If length is given and is non-negative, + then subject will be examined + for length characters after the starting + position. + + + If length is given and is negative, + then subject will be examined from the + starting position up to length + characters from the end of subject. - + &reftitle.returnvalues; - Returns the length of the segment as an integer. + Returns the length of the initial segment of subject + which consists entirely of characters not in mask. + + + When a start parameter is set, the returned length + is counted starting from this position, not from the beginning of + subject. + + - + &reftitle.examples; @@ -80,11 +127,15 @@ $a = strcspn('abcd', 'apple'); $b = strcspn('abcd', 'banana'); $c = strcspn('hello', 'l'); $d = strcspn('hello', 'world'); +$e = strcspn('abcdhelloabcd', 'abcd', -9); +$f = strcspn('abcdhelloabcd', 'abcd', -9, -5); var_dump($a); var_dump($b); var_dump($c); var_dump($d); +var_dump($e); +var_dump($f); ?> ]]> @@ -95,16 +146,18 @@ int(0) int(0) int(2) int(2) +int(5) +int(4) ]]> - + &reftitle.notes; ¬e.bin-safe; - + &reftitle.seealso; @@ -113,7 +166,7 @@ int(2) - +