quotemeta

(PHP 4, PHP 5, PHP 7, PHP 8)

quotemetaEscapa meta caracteres

Descrição

quotemeta(string $string): string

Retorna uma versão de da string com uma barra invertida (\) antes de cada caractere que esteja neste conjunto:

. \ + * ? [ ^ ] ( $ )

Parâmetros

string

A string de entrada.

Valor Retornado

Retorna a string com os meta caracteres escapados ou false se uma string vazia for fornecida no parâmetro string.

Exemplos

Exemplo #1 Exemplo de quotemeta()

<?php

var_dump
(quotemeta('PHP é uma linguagem de script popular. Rápida, flexível e pragmática.'));
?>

O exemplo acima produzirá:

string(71) "PHP é uma linguagem de script popular\. Rápida, flexível e pragmática\."

Notas

Nota: Esta função é compatível com dados binários.

Veja Também

  • addslashes() - Adiciona barras a uma string
  • addcslashes() - Escata string com barras invertidas no estilo C
  • htmlentities() - Converte todos os caracteres aplicáveis em entidades HTML
  • htmlspecialchars() - Converte caracteres especiais para entidades HTML
  • nl2br() - Insere quebras de linha HTML antes de todos os caracteres de nova linha em um string
  • stripslashes() - Desfaz os escapes de uma string escapada
  • stripcslashes() - Remove o escape de strings escapadas com addcslashes
  • preg_quote() - Quote regular expression characters

add a note

User Contributed Notes 3 notes

up
15
kumarkulandai at gmail dot com
14 years ago
<?php
$str
= "Hello world. (can you hear me?)";
echo
quotemeta($str);
?>

The output of the code above will be:
Hello world\. \(can you hear me\?\)
up
10
George Adams
18 years ago
Took me a while to realize this was NOT the command I wanted for escaping potentially harmful characters in a string that would be used as part of a system command. Instead, I needed either escapeshellarg() (http://www.php.net/manual/en/function.escapeshellarg.php) or escapeshellcmd() (http://www.php.net/manual/en/function.escapeshellcmd.php)
up
5
Anonymous
23 years ago
This function escapes characters that have special meaning in regular expressions. preg_quote() <http://php.net/manual/en/function.preg-quote.php> has similar functionality, but is more powerful since it escapes more characters (including one user-specified character).
To Top