strscan / strscan
Simple string tokenizer for lexical scanning operations
Installs: 118 671
Dependents: 3
Suggesters: 0
Security: 0
Stars: 13
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-12-21 13:31:27 UTC
README
strscan-php is a simple string tokenizer for lexical scanning operations. It's a PHP port of strscan-js, which in turn is a JavaScript port of the Ruby library with the same name. This library assumes the mbstring extension is enabled and all strings to be UTF-8.
Installation
The recommended way to install strscan-php is through composer.
Usage
<?php include '/path/to/StrScan/StringScanner.php'; use StrScan\StringScanner; $s = new StringScanner("This is a test"); $s->scan("/\w+/"); # => "This" $s->scan("/\w+/"); # => null $s->scan("/\s+/"); # => " " $s->scan("/\s+/"); # => null $s->scan("/\w+/"); # => "is" $s->hasTerminated(); # => false $s->scan("/\s+/"); # => " " $s->scan("/(\w+)\s+(\w+)/"); # => "a test" $s->getMatch(); # => "a test" $s->getCapture(0); # => "a" $s->getCapture(1); # => "test" $s->hasTerminated(); # => true
License
strscan-php is released under the MIT license.
Acknowledgments
The original strscan-js was written by Sam Stephenson.