Ratings | | Unique User Downloads | | Download Rankings |
Not yet rated by the users | | Total: 47 | | All time: 10,758 This week: 673 |
Example
<?php
use Mateodioev\StringMatcher\{Config, Matcher};
require __DIR__ . '/vendor/autoload.php';
$conf = new Config;
// match email's
$conf->addFormat('mail', "([a-z0-9!\#$%&'*+\\/=?^_`{|}~-]+(?:\\.[a-z0-9!\#$%&'*+\\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9]))");
# $conf->addFormat('c', '([\d.]+)');
$matcher = new Matcher('/{name}?/{aaaa}/{mail:umail}?/', $conf);
$text = '/nombre/asds/customemail@mail.com/';
var_dump($matcher->isValid($text, true));
$vars = $matcher->match($text, true);
echo json_encode($vars, JSON_PRETTY_PRINT);
|
Details
String Vars
Get vars from a string
Install
composer require mateodioev/string-vars
use Mateodioev\StringVars\{Config, Matcher};
Example:
$matcher = new Matcher(format: "Hello {name}");
// Validate input
var_dump($matcher->isValid('Hello Juan')); // true
var_dump($matcher->isValid('Hello _ Juan')); // false
$vars = $matcher->match('Hello Juan'); // $vars contain an array of parameters
var_dump($vars['name']); // "Juan"
Match with data types
// "w": all string
// "d": all numbers
// "f": all decimals
// "all": all characters
// "": all characters except /
$matcher = new Matcher(format: "Hello {w:name}");
Using custom formats
$conf = new Config();
// This match only decimals numbers
$conf->addFormat('c', '([\d]+\.[\d]+)');
$matcher = new Matcher('The price is {c:price}', $conf);
var_dump($matcher->isValid('The price is 33.03')); // true
var_dump($matcher->isValid('The price is 33')); // false
$vars = $matcher->match('The price is 33.03');
var_dump($vars['price']); // "33.03"
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.