PHP code example of magnusjt / regtemplate_php

1. Go to this page and download the library: Download magnusjt/regtemplate_php 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/ */

    

magnusjt / regtemplate_php example snippets


$template = \RegTemplate\RegTemplate('some/dir');

# Parse a template from a file inside the base directory
$template->parse_template_from_file('file_inside_some_dir.txt');

# Or parse from a string:
# $template->parse_template('Some number: {{ number|digits }}');

# Match an output string against the template. Name=>value array returned.
$name_value = $template->match('Some number: 64');

# Match all. If the regex matches several times, return a list of list of name=>value arrays:
$match_list = $template->match_all('Some number: 64, Some number: 65');

$template->set_rule('digits', '\d+');
$template->set_rule('on_or_off', '(?:on|off)');

# Default rule if no rule is given in the template
$template->set_default_rule('\S+');

$template->parse_template('{{ number|reg="\d\d\d" }}

$template->set_ignore_whitespace(true);

$template->set_variable_tokens('{{', '}}');

$template->set_ignore_var_name('any');
`
composer