PHP preg_quote() Function

PHP mkdir() Function
PHP preg_split() Function

In this article, you will learn about the preg_quote function in PHP. The preg_quote() function in PHP adds a backslash to characters that have a special meaning in regular expressions so that searches for the literal characters can be done. This function is useful when using user input in regular expressions.

what is the syntax of the PREG_QUOTE function in php?

preg_quote(input, delimiter)
inputRequired. The string to be escaped
delimiterOptional. Defaults to null. This parameter expects a single character indicating which delimiter the regular expression will use. When provided, instances of this character in the input string will also be escaped with a backslash

examples of the PREG_QUOTE function

Example 1. In this example, we use preg_quote() to safely use special characters in a regular expression.

$search = preg_quote("://", "/");
$input = '';
$pattern = "/$search/";
if(preg_match($pattern, $input)) {
  echo "The input is a URL.";
} else {
  echo "The input is not a URL.";
PHP mkdir() Function
PHP preg_split() Function

Tutor Network

Share this

Learn PHP from A to Z