$value) { if (!empty($value)) { continue; } $placeholder = $delimiters[0] . $placeholder . $delimiters[1]; $format = preg_replace('/\[[^\[]*' . preg_quote($placeholder) . '[^\]]*\]/', '', $format); } $chars = str_split($format); $length = count($chars); for ($i = 0; $i < $length; $i++) { if (in_array($chars[$i], ['[', ']']) && ($i == 0 || $chars[$i - 1] != '\\')) { unset($chars[$i]); } } return str_replace(['\\[', '\\]'], ['[', ']'], implode($chars)); } }