Simple data anonymization
Jump to navigation
Jump to search
Simple data anonymization
ex: 王小明 --> 王O明
- Excel: =REPLACE(A2, 2, 1, O)[1]
- PHP: using regular_replace
$string = '王小明'; $pattern = '/^(\X)(\X)(\X+)/u'; $replacement = '$1O$3'; echo preg_replace($pattern, $replacement, $string);
- MySQL: using SUBSTRING
SELECT CONCAT(SUBSTRING_INDEX('王小明', SUBSTRING('王小明', 2, 1), 1),
SUBSTRING('王小明', 2, 1),
SUBSTRING_INDEX('王小明', SUBSTRING('王小明', 2, 1), -1));
ex: 王小明 --> 王OO
- MySQL: SELECT CONCAT(LEFT("王小明", 1), 'OO')
reference
further reading