Some native PHP string functions have a parameter which is a string of one or more unordered characters (also referred to as a "character mask"). In some cases, character ranges can be expressed using double-dot syntax.
For example: echo trim('foo24, '0..9'); prints foo because 2 and 4 fall within the 0 through 9 range.
What are the other native PHP string functions with the same feature?
CodePudding user response:
Native PHP string functions that respect double-dot range expressions:
addcslashes()(Demo)echo addcslashes('adobe', 'a..e'); // \a\do\b\echop()-- alias ofrtrim()(Demo)echo chop('adobe', 'a..e'); // adoltrim()(Demo)echo ltrim('adobe', 'a..e'); // obertrim()(Demo)echo rtrim('adobe', 'a..e'); // adostr_word_count()(Demo)var_export( str_word_count('do not break|on|pipe', 1, '{..}') ); // ['do', 'not', 'break|on|pipe']trim()(Demo)echo trim('adobe', 'a..e'); // oucwords()(Demo)`echo ucwords('backdoorman', 'a..e'); // BaCkdOormaN
Here are some native functions where ranged expressions are not expanded, but might be reasonable candidates for the feature:
strcspn()(Demo) (expansion would be reasonable)echo strcspn('cdplayer', 'b..e'); // 6 // 0 if range enabledstrpbrk()(Demo) (expansion would be reasonable)echo strpbrk('stackoverflow', 'b..f'); // flow // ckoverflow if range enabledstrspn()(Demo) (expansion would be reasonable)echo strspn('adobe', 'a..e'); // 1 // 2 if range enabledstrtok()(Demo) (expansion would be reasonable)echo strtok('toddler', 'a..e'); // toddl // to if range enabledstrtr()(Demo) (not a good candidate because character order matters)echo strtr('adobe', 'a..e', 'A..E'); // AdobE // ADoBE if range enabled
