Download the PHP package phlak/splat without Composer
On this page you can find all versions of the php package phlak/splat. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package splat
Glob-like file and pattern matching utility.
Requirements
- PHP >= 8.1
Installation
Install Splat with Composer.
composer require phlak/splat
Then import the Glob
or Pattern
classes as needed.
Patterns
Glob
methods accept a $pattern
as the first parameter. This can be a string
or an instance of \PHLAK\Splat\Pattern
.
A pattern string may contain one or more of the following special matching expressions.
Matching Expressions
?
matches any single character*
matches zero or more characters excluding/
(\
on Windows)**
matches zero or more characters including/
(\
on Windows)[abc]
matches a single character from the set (i.e.a
,b
orc
)[a-c]
matches a single character in the range (i.e.a
,b
orc
)[!abc]
matches any character not in the set (i.e. nota
,b
orc
)[!a-c]
matches any character not in the range (i.e. nota
,b
orc
){foo,bar,baz}
matches any pattern in the set (i.e.foo
,bar
orbaz
)- Sets may contain other matching patterns (i.e.
{foo,ba[rz]}
)
- Sets may contain other matching patterns (i.e.
Assertions
The following assertions can be use to assert that a string is followed by, or not followed by, another pattern.
(=foo)
matches any string that also containsfoo
(!foo)
matches any string that does not also containfoo
For example, a pattern of *.tar(!.{gz,xz})
will match a string ending with
.tar
or .tar.bz
but not tar.gz
or tar.xz
.
Converting Patterns To Regular Expressions
Glob patterns can be converted to a regular expression pattern.
You can control regular expression line anchors via the $anchors
parameter.
Pattern Character Escaping
Sometimes you may have characters in a string that shouldn't be treated as
matching expression characters. In those situations you can escape any character
by preceeding it with a backslash (\
).
You may also escape glob pattern characters from a string programmatically with
the Pattern::escape()
method.
Methods
Files In
Get a list of files in a directory matching a glob pattern.
Returns a Symfony Finder Component
containing the files matching the glob pattern within the specified directory
(e.g. foo.txt
, foo/bar.txt
, foo/bar/baz.txt
, etc.).
Exact Match
Test if a string matches a glob pattern.
Match Start
Test if a string starts with a glob pattern.
Match End
Test if a string ends with a glob pattern.
Match Within
Test if a string contains a glob pattern.
Filter an Array (of Strings)
Filter an array of strings to values matching a glob pattern.
Reject an Array (of Strings)
Filter an array of strings to values not matching a glob pattern.
Changelog
A list of changes can be found on the GitHub Releases page.
Troubleshooting
For general help and support join our GitHub Discussion or reach out on Bluesky.
Please report bugs to the GitHub Issue Tracker.
Copyright
This project is licensed under the MIT License.