') !== false ) { if ( $tmp_source && $tmp_dest ) { $in_ary[$tmp_source] = $tmp_dest; } $tmp_source = ''; $tmp_dest = ''; $in_rec = false; } else if ( preg_match('!(.*)!', $in_line, $matches) ) { $tmp_source = $matches[1]; $tmp_source = fix_string($tmp_source); } else if ( preg_match('!(.*)!', $in_line, $matches) ) { $tmp_dest = $matches[1]; $tmp_dest = fix_string($tmp_dest); } } else { if ( strpos($in_line, 'DIAL:FULL') !== false ) { $in_rec = true; } } } fputs($fp_new, '{' . PHP_EOL); ksort($in_ary); $max = count($in_ary); $counter = 0; foreach ($in_ary as $key => $value) { $counter++; $out_line = sprintf(' "%s": "%s"', $value, $key); if ( $counter < $max) { $out_line .= ','; } fputs($fp_new, $out_line . PHP_EOL); } fputs($fp_new, '}' . PHP_EOL); fclose($fp_new); } catch (Exception $e) { } fclose($fp); } function fix_string($str) { $str = preg_replace('/\(.+?\)$/', '', $str); $str = rtrim($str, ' '); $str = str_replace(' ', '_', $str); $str = str_replace('/', '_', $str); $str = str_replace("\\", '_', $str); $str = str_replace(':', '_', $str); $str = str_replace('*', '_', $str); $str = str_replace('?', '_', $str); $str = str_replace('"', '_', $str); $str = str_replace('<', '_', $str); $str = str_replace('>', '_', $str); $str = str_replace('|', '_', $str); $str = str_replace('"', "_", $str); $str = str_replace(''', "'", $str); return $str; }