筆記
設定字串欲隱藏的前後位置,並取代為指定字符
function replaceSymbol($string, $symbol, $start = 0, $end = 0) { $length = mb_strlen($string); if ($length === 0) { return ''; } $start = (int) $start; $end = (int) $end; $mid = (int) $length - $start - $end; if ($mid <= 0) { return $string; } $startWord = mb_substr($string, 0, $start); $endWord = ($end === 0) ? '' : mb_substr($string, 0 - $end); $midWord = str_repeat($symbol, $mid); return $startWord . $midWord . $endWord; }