https://github.com/tylercd100/laravel-placeholders
Find and replace placeholders in a string
https://github.com/tylercd100/laravel-placeholders
laravel placeholders strings
Last synced: about 2 months ago
JSON representation
Find and replace placeholders in a string
- Host: GitHub
- URL: https://github.com/tylercd100/laravel-placeholders
- Owner: tylercd100
- License: mit
- Created: 2017-03-01T03:38:25.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-12-17T07:50:23.000Z (over 3 years ago)
- Last Synced: 2025-03-18T13:28:54.868Z (2 months ago)
- Topics: laravel, placeholders, strings
- Language: PHP
- Homepage:
- Size: 8.79 KB
- Stars: 12
- Watchers: 2
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Find and Replace placeholder strings in Laravel 5
[](https://github.com/tylercd100/laravel-placeholders/releases)
[](LICENSE.md)
[](https://travis-ci.org/tylercd100/laravel-placeholders)
[](https://scrutinizer-ci.com/g/tylercd100/laravel-placeholders/?branch=master)
[](https://scrutinizer-ci.com/g/tylercd100/laravel-placeholders/?branch=master)
[](https://www.versioneye.com/user/projects/56f3252c35630e0029db0187)
[](https://packagist.org/packages/tylercd100/laravel-placeholders)## Installation
Install via [composer](https://getcomposer.org/) - In the terminal:
```bash
composer require tylercd100/laravel-placeholders
```Now add the following to the `providers` array in your `config/app.php`
```php
Tylercd100\Placeholders\ServiceProvider::class
```and this to the `aliases` array in `config/app.php`
```php
"Placeholders" => Tylercd100\Placeholders\Facades\Placeholders::class,
```
Then you will need to run these commands in the terminal in order to copy the config file
```bash
php artisan vendor:publish --provider="Tylercd100\Placeholders\ServiceProvider"
```## Usage
```php
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
```### Style
```php
// 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
```### Errors
```php
// Throw an error if one is missed
Placeholders::setThorough(true) // This is the default
Placeholders::parse("I like [fruit]s and [veg]s", [
'fruit' => 'orange',
]); //Throws an Exception: Could not find a replacement for [veg]
```