Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Quote string with slashes in a C style
<?php addcslashes(string $string, string $characters): string
<?php $prefixEscaped = preg_quote($prefix);
$foundWithPrefix = addcslashes($prefix.$found, '$\\');
$pattern = "/(?<!{$prefixEscaped}){$foundEscaped}(?![^<]*(?<![?=-])>)/mUi";
<?php $suffixEscaped = preg_quote($suffix);
$foundWithSuffix = addcslashes($found.$suffix, '$\\');
$pattern = "/{$foundEscaped}(?!\w)(?!{$suffixEscaped})(?![^<]*(?<![?=-])>)/mUi";
<?php $value = str_replace("'", "''", $value);
return "'" . addcslashes($value, "\000\n\r\\\032") . "'";
}
public function exec(string $sql): int
<?php {
return preg_replace(
'~([' . preg_quote($this->getLikeWildcardCharacters() . $escapeChar, '~') . '])~u',
addcslashes($escapeChar, '\\') . '$1',
$inputString
);
}
<?php $loopedText = $associative ? $parses->first() : $parses->implode('');
$text = $this->preg_replace('/'.preg_quote($match[0][0], '/').'/m', addcslashes($loopedText, '\\$'), $text, 1);
}
return $text;
<?php $replacement = $this->valueToLiteral($replacement);
}
$text = $this->preg_replace('/'.preg_quote($tag, '/').'/m', addcslashes($replacement, '\\$'), $text, 1);
$text = $this->injectExtractions($text, 'nested_tag_pair');
}
<?php $conditional .= ': ?>';
$text = $this->preg_replace('/'.preg_quote($match[0], '/').'/m', addcslashes($conditional, '\\$'), $text, 1);
}
$text = $this->preg_replace($this->conditionalElseRegex, '<?php else: ?>', $text);
<?php $links = Preg::replace(
'{'.preg_quote($match[1]).'$}',
addcslashes(',' . $this->newline . $this->indent . $this->indent . JsonFile::encode($package).': '.JsonFile::encode($constraint) . $match[1], '\\$'),
$links
);
} else {
<?php if ($append) {
$children = Preg::replace(
'#'.$whitespace.'}$#',
addcslashes(',' . $this->newline . $this->indent . $this->indent . JsonFile::encode($name).': '.$this->format($value, 1) . $whitespace . '}', '\\$'),
$children
);
} else {
<?php $children = Preg::replace(
'#^{'.$whitespace.'#',
addcslashes('{' . $whitespace . JsonFile::encode($name).': '.$this->format($value, 1) . ',' . $this->newline . $this->indent . $this->indent, '\\$'),
$children
);
}
<?php if (Preg::isMatch('#[^{\s](\s*)\}$#', $this->contents, $match)) {
$this->contents = Preg::replace(
'#'.$match[1].'\}$#',
addcslashes(',' . $this->newline . $this->indent . JsonFile::encode($key). ': '. $content . $this->newline . '}', '\\$'),
$this->contents
);
<?php $this->contents = Preg::replace(
'#\}$#',
addcslashes($this->indent . JsonFile::encode($key). ': '.$content . $this->newline . '}', '\\$'),
$this->contents
);