PHP code example of bizarg / variable-parser
1. Go to this page and download the library: Download bizarg/variable-parser 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/ */
bizarg / variable-parser example snippets
return [
'path' => '', // Path to variables
'signOpen' => '[[',
'signClose' => ']]',
'variableFrom' => [
'class' => false,
'relation' => true
]
];
use Bizarg\VariableParser\VariableParser;
$variableData = ['user' => User::find(1)]; /*or*/ (new VariableData())->setUser(User::find(1));
$content = 'Name: [[user.name]]<br>
Email: [[user.email]]<br>
Title: [[article.title]]<br>
Custom: [[custom]]<br>
Slug: [[article.slug]]<br>';
$parser = new VariableParser();
$parser->setContent($content);//string
$parser->setVariableData($variableData);//array|object
$content = $parser->parseContent();
$content = (new VariableParser($content, $variableData))->parseContent();
$parser->setData([
'user.name' => 'White Wolf',
'custom' => 'value',
]);
$parser->setSignOpen('{{');
$parser->setSignClose('}}');
$parser->setPreview(true);// if used class
$parser->setContent('Name: [[user.name]]<br>');