Skip to content

Instantly share code, notes, and snippets.

@Fray117
Created August 12, 2021 05:41
Show Gist options
  • Save Fray117/0c71992128cd5cae5e4784184f4b277b to your computer and use it in GitHub Desktop.
Save Fray117/0c71992128cd5cae5e4784184f4b277b to your computer and use it in GitHub Desktop.
Simple censor for sensitive data
<?php
/**
* Censor the part of string
*
* @param mixed $str
* @param mixed $mask
* @param int $intensity
* @param int $reveal
* @return string
*/
function censor(mixed $str, mixed $mask = '*', int $intensity = 2, int $reveal = 2) {
return substr_replace(
$str,
str_repeat(
$mask, (
(strlen($str) - $intensity) >= 0
) ? (
strlen($str) - $intensity
)
: 1),
$reveal);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment