PHP code example of mpesic381 / laravel-placeholders

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

    

mpesic381 / laravel-placeholders example snippets


use Placeholders;

// Basic
Placeholders::parse("I like [fruit]s and [veg]s", [
	'fruit' => 'orange',
	'veg' => 'cucumber'
]); //I like oranges and cucumbers

// Globally
Placeholders::set("fruit", "apple");
Placeholders::set("veg", "carrot");
Placeholders::parse("I like [fruit]s and [veg]s"); // I like apples and carrots

// Change the style
Placeholders::setStyle("{{", "}}");
Placeholders::parse("I like {{fruit}}s and {{veg}}s", [
	'fruit' => 'lemon',
	'veg' => 'string bean'
]); //I like lemons and string beans

// Throw an error if one is missed
Placeholders::setBehavior('error')
Placeholders::parse("I like [fruit]s and [veg]s", [
	'fruit' => 'orange',
]); //Throws an Exception: Could not find a replacement for [veg]

// Delete the placeholder from the output if it is missing.
Placeholders::setBehavior('skip')
Placeholders::parse("I like [fruit]s and [veg]s", [
	'fruit' => 'orange',
]); // I like oranges and s

Placeholders::setBehavior('preserve')
Placeholders::parse("I like [fruit]s and [veg]s", [
	'fruit' => 'orange',
]); // I like oranges and [veg]s


bash
php artisan vendor:publish --provider="MPesic381\Placeholders\PlaceholdersServiceProvider"