Created
August 12, 2021 05:41
-
-
Save Fray117/0c71992128cd5cae5e4784184f4b277b to your computer and use it in GitHub Desktop.
Simple censor for sensitive data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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