Skip to content

Commit

Permalink
Update Helper.php
Browse files Browse the repository at this point in the history
  • Loading branch information
rlzdesenv authored Dec 20, 2024
1 parent 75cfe27 commit b7c5695
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,49 @@ public static function substr($string, $start, $length = null): ?string
return mb_substr((string)$string, $start, $length);
}

static function mask($str, $mask)
{
$str = self::getNumber($str);

if (empty($str)) {
return $str;
}

$text = '';
$k = 0;
for ($i = 0; $i <= Helper::strlen($mask) - 1; $i++) {
if ($mask[$i] == '#') {
if (isset ($str[$k]))
$text .= $str[$k++];
} else {
if (isset ($mask[$i]))
$text .= $mask[$i];
}
}
return $text;
}

static function getNumber($str): array|string|null
{
if (is_null($str)) {
return null;
}
return preg_replace("/[^0-9]/", "", $str);
}

public static function strlen($str): int
{
if (is_null($str)) {
return 0;
}
return strlen($str);
}

public static function alfaNumerico($str): string|null
{
if (is_null($str)) {
return null;
}
return preg_replace('/[^a-zA-Z0-9 ]/', '', $str);
}
}

0 comments on commit b7c5695

Please sign in to comment.