PHP code example of jkque / laravel-string-replace

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

    

jkque / laravel-string-replace example snippets


use Jkque\StringReplace\StringReplace;

use App\User;

class UserStringReplace extends StringReplace
{
    public function __construct(User $user)
    {
        $this->variables([
            '@name' => $user->name,
        ]);
    }
}

use Jkque\StringReplace\StringReplace;

$string = 'We are awesome <p>in php</p> replacethis';

$string = StringReplace::content($string)
    ->variables([
        'replacethis' => 'coding',
    ])
    ->replace(); // the ending method to be called

$string->when($somecondtion, function ($string) {
 // do something;
})

use Jkque\StringReplace\StringReplace;

class RemoveBadWords extends StringReplace
{
    public function __construct()
    {
        $this->variables([
            'badword' => '*',
        ]);
    }
}
 php
$remove_characters = ['<p>', '</p>', '&#39;', '&#039;', '<h2>', '</h2>', '<strong>', '</strong>', '&nbsp;', '&#63;','@name', '&rsquot;', '&quot;', '@firstname'];
$replace_with = ['', '', "'", "'", '', '', '', '', '', '?', $user->name, "'", '"', $user->first_name];

$message = str_replace($remove_characters, $replace_with, $message);
 php
use Jkque\StringReplace\StringReplace;

$message = StringReplace::content($string)
    ->when($user, function ($string) use($user) {
        return $string->with(new UserStringReplace($user));
    })
    ->variables([
        '&#39;' => "'",
        '&#63;' => '?'
    ])
    ->replace();
bash
php artisan vendor:publish --provider="Jkque\StringReplace\StringReplaceServiceProvider"