PHP code example of yuanqing / extract

1. Go to this page and download the library: Download yuanqing/extract library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yuanqing / extract example snippets


use yuanqing\Extract\Extract;

$e = new Extract('{{ foo.bar }}, {{ foo.baz }}!');
$e->extract('Hello, World!'); #=> ['foo' => ['bar' => 'Hello', 'baz' => 'World']]

    $e = new Extract('{{ foo: s }}, {{ bar: s }}!');
    $e->extract('Hello, World!'); #=> ['foo' => 'Hello', 'bar' => 'World']
    $e->extract('Hola, World!'); #=> ['foo' => 'Hola', 'bar' => 'World']

    $e = new Extract('{{ foo: 5s }}, {{ bar: 5s }}!');
    $e->extract('Hello, World!'); #=> ['foo' => 'Hello', 'bar' => 'World']
    $e->extract('Hola, World!'); #=> null
    

    $e = new Extract('{{ day: d }}-{{ month: d }}-{{ year: d }}');
    $e->extract('31-12-2014'); #=> ['day' => 31, 'month' => 12, 'year' => 2014]
    $e->extract('31-12-14'); #=> ['day' => 31, 'month' => 12, 'year' => 14]
    $e->extract('31-Dec-2014'); #=> null

    $e = new Extract('{{ day: 2d }}-{{ month: 2d }}-{{ year: 4d }}');
    $e->extract('31-12-2014'); #=> ['day' => 31, 'month' => 12, 'year' => 2014]
    $e->extract('31-12-14'); #=> null
    

    $e = new Extract('{{ tau: f }}, {{ pi: f }}');
    $e->extract('6.28, 3.14'); #=> ['tau' => 6.28, 'pi' => 3.14]
    $e->extract('tau, pi'); #=> null

    $e = new Extract('{{ tau: 1.f }}, {{ pi: 1.f }}');
    $e->extract('6.28, 3.14'); #=> ['tau' => 6.28, 'pi' => 3.14]
    $e->extract('06.28, 03.14'); #=> null

    $e = new Extract('{{ tau: .2f }}, {{ pi: .2f }}');
    $e->extract('6.28, 3.14'); #=> ['tau' => 6.28, 'pi' => 3.14]
    $e->extract('6.283, 3.142'); #=> null

    $e = new Extract('{{ tau: 1.2f }}, {{ pi: 1.2f }}');
    $e->extract('6.28, 3.14'); #=> ['tau' => 6.28, 'pi' => 3.14]
    $e->extract('6.3, 3.1'); #=> null