PHP Classes

udPattern: A simple way to check strings against patterns.

Recommend this page to a friend!
  Info   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (4 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 650 All time: 4,928 This week: 117Up
Version License PHP version Categories
udpattern 1.0BSD License4.0Text processing
Description 

Author

udPattern allows you to store patterns and to check strings against them. It should be perfect for matching URLs and filenames.

Just register the patterns you want to use and then call the TestPattern function to check if it is a valid string. You can use accept(+) or reject(-) to all patterns as well as wildcards.

If you are experienced with regular expressions you might do it faster but probably not as easy.

Picture of Thomas Björk
  Performance   Level  
Name: Thomas Björk <contact>
Classes: 11 packages by
Country: Sweden Sweden
Innovation award
Innovation award
Nominee: 3x

Details

/*============================================================================== Quick documentation ================================================================================ TestPattern($check, $easyTest, $delimiter) ------------------------------------------ Test a pattern against the registered patterns in the object. returns returns a positive number for any accepted match returns a negative number for any rejected match returns 0 for any any test that doesn't match anything unless $easyTest is set to false, then it returns false for any unmatched test $check the pattern to test $easyTest if set to false the test will return false if no matching found $delimiter the delimiter used CleanPattern($pattern, $delimiter) ---------------------------------- Clean up a pattern. Removes redundant information and reorders the pattern. returns a clean pattern $pattern the pattern to clean $delimiter the delimiter used CheckPattern($pattern1, $pattern2, $delimiter) ---------------------------------------------- Check is $pattern2 can be matched against $pattern1. Any wildcard in $pattern2 will be ignored. returns true if match false if not $delimiter the delimiter used SetPatternArray($array) ----------------------- Set a pre-defined array of patterns. $array a one-dimension array with patterns $delimiter the delimiter used SetPatternString($pattern, $delimiter) -------------------------------------- Set a string of patterns $pattern a string of patterns $delimiter the delimiter used to separate patterns ClearPatterns() --------------- Clear the internal pattern array Add($pattern, $delimiter) ------------------------- Add a pattern to the internal array. All patterns that are added will be cleaned and tested for redundancy. $pattern the pattern to add $delimiter the delimiter used Validation order ================ The validation of a pattern is made in the added order. First added is first checked. If you use the Add function then the added pattern vill be tested against previously added patterns. If the new pattern is redundant then it will not be added. Patterns ======== * can be matched against any string % can be matched against any string that doesn't contain the delimiter used ? can be matched against one character that isn't equal to the delimiter patterns that starts with *.zzz.zzz match zzz.zzz patterns that starts with %.zzz.zzz doesn't match zzz.zzz patterns like zzz*.zzz match zzzzz.zzz and zzz.zzz.zzz patterns like zzz%.zzz match zzzzz.zzz but not zzz.zzz.zzz patterns like *%.zzz.zzz match zzz.zzz.zzz and zzz.zzz.zzz.zzz and .zzz.zzz but not zzz.zzz patterns like *?.zzz.zzz match zzz.zzz.zzz and zzz.zzz.zzz.zzz but not .zzz.zzz and zzz.zzz Cleaning ======== ** is redundant and replaced with * %% is redundant and replaced with % .*.* is redundant and replaced with .* *.*. is redundant and replaced with *. ?* is reordered to *? ?% is reordered to %? %* is reordered to *% Note! In the sections Patterns and Cleaning the default $delimiter (.) is used. ==============================================================================*/

  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example A quick example
Accessible without login Plain text file LICENSE Data License file
Accessible without login Plain text file README.md Data Updated readme to markdown
Accessible without login Plain text file readme.txt Doc. Quick documentation
Plain text file udpattern.php Class Implements the class udPattern

 Version Control Unique User Downloads Download Rankings  
 80%
Total:650
This week:0
All time:4,928
This week:117Up