Update the format_string function

This commit is contained in:
FusionPBX
2021-10-08 16:38:48 -06:00
committed by GitHub
parent e701c9c261
commit d682dcc717
+16 -1
View File
@@ -724,9 +724,18 @@ function switch_module_is_running($fp, $mod) {
//switch_module_is_running('mod_spidermonkey'); //switch_module_is_running('mod_spidermonkey');
//format a number (n) replace with a number (r) remove the number //format a number (n) replace with a number (r) remove the number
function format_string ($format, $data) { function format_string($format, $data) {
//preset values
$x=0; $x=0;
$tmp = ''; $tmp = '';
//count the characters
$format_count = substr_count($format, 'x');
$format_count = $format_count + substr_count($format, 'R');
$format_count = $format_count + substr_count($format, 'r');
//format the string if it matches
if ($format_count == strlen($data)) {
for ($i = 0; $i <= strlen($format); $i++) { for ($i = 0; $i <= strlen($format); $i++) {
$tmp_format = strtolower(substr($format, $i, 1)); $tmp_format = strtolower(substr($format, $i, 1));
if ($tmp_format == 'x') { if ($tmp_format == 'x') {
@@ -740,7 +749,13 @@ function format_string ($format, $data) {
$tmp .= $tmp_format; $tmp .= $tmp_format;
} }
} }
}
if (strlen($tmp) == 0) {
return $data;
}
else {
return $tmp; return $tmp;
}
} }
//get the format and use it to format the phone number //get the format and use it to format the phone number