PHP code example of ridwanpr / string-masker

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

    

ridwanpr / string-masker example snippets


use Ridwan\StringMasker\EmailMasker;

$email = "[email protected]";
$maskedEmail = EmailMasker::maskEmail($email, [
    'local' => ['mask' => '*', 'start' => 0, 'length' => 3],
    'domain' => ['mask' => '*', 'start' => 0, 'length' => 3],
    'maskAll' => null // Options: 'local', 'domain', 'both'
]);
echo $maskedEmail; // Outputs: "***r@***ple.com"

use Ridwan\StringMasker\CreditCardMasker;

$cardNumber = "1234-5678-9012-3456";
$maskedCardNumber = CreditCardMasker::maskCardNumber($cardNumber, [
    'maskAll' => false,
    'mask' => '*',
    'positions' => [1, 2, 5],
    'showDashes' => true
]);
echo $maskedCardNumber;

use Ridwan\StringMasker\PhoneMasker;

$phone = "+621234567890";
$maskedPhone = PhoneMasker::maskPhone($phone, [
    'maskAll' => false,
    'mask' => '*',
    'positions' => [3, 4, 5]
]);
echo $maskedPhone;

use Ridwan\StringMasker\TextMasker;

$text = "Hello, World!";
$maskedText = TextMasker::maskText($text, [
    'maskAll' => false,
    'mask' => '*',
    'positions' => [0, 7],
    'separators' => [' ', ',', '!']
]);
echo $maskedText;

use Ridwan\StringMasker\ContentMasker;

$message = "My bank account number is 12345678 and my password is secret.";
$maskedMessage = ContentMasker::maskContent($message, [
    'mask' => '*',
    'words' => ['bank account', 'password'],
]);
echo $maskedMessage;