PHP code example of lukaswhite / token-strings

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

    

lukaswhite / token-strings example snippets


[
	'FORENAME'  =>  'Joe',
	'SURNAME'   =>  'Bloggs',
]

use Lukaswhite\TokenStrings\Substitutor( );

$substitutor = new Substitutor(
	'Dear [[FORENAME]] [[SURNAME]],',
	[
		'forename'  =>  'Joe',
		'surname'   =>  'Bloggs',
	]
);

$replaced = $substitutor->run( );
// or
$replaced = ( string ) $substitutor;

$substitutor->setContent( 'Hey [[FORENAME]]' );

$substitutor->addToken( 'age', 43 );

$substitutor->clearTokens( );

$substitutor->setOpeningTag( '{{' )->setClosingTag( '}}' );

$substitutor->setOpeningTag( '{{' );

class Person {

    private $forename;

    private $surname;

    public function __construct( $forename, $surname )
    {
        $this->forename = $forename;
        $this->surname = $surname;
    }
    
    public function __toString( ) 
    {
        return sprintf( '%s %s', $this->forename, $this->surname );
    }
}

$substitutor = new Substitutor(
	'Dear [[NAME]],',
	[
		'NAME'  =>  new Person( 'Joe', 'Bloggs' ),
	]
);