Escapes a string.
string $string The string to be escaped:
string $char The character to be escaped:
string $with The character to be used for escaping:
string The escaped string
private static function escape($string, $char, $with) {
$escaped = false;
$output = '';
foreach (str_split($string) as $symbol) {
if ($escaped) {
$output .= $symbol;
$escaped = false;
continue;
}
if ($symbol === $char) {
$output .= $with . $char;
continue;
}
if ($symbol === $with) {
$escaped = true;
}
$output .= $symbol;
}
return $output;
}