PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Mateo   PHP String Match Variables   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP String Match Variables
Extract values from strings using tag patterns
Author: By
Last change:
Date: 1 year ago
Size: 584 bytes
 

Contents

Class file image Download
<?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);