PHP 8.5.0 Alpha 1 available for testing

quotemeta

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

quotemetaProtege los metacaracteres

Descripción

quotemeta(string $string): string

Devuelve la cadena str después de haber introducido una barra invertida (\) delante de todos los caracteres siguientes:

. \ + * ? [ ^ ] ( $ )

Parámetros

string

La cadena de entrada.

Valores devueltos

Devuelve la cadena cuyos metacaracteres han sido protegidos o false si una cadena vacía es proporcionada en el argumento string.

Ejemplos

Ejemplo #1 Ejemplo con quotemeta()

<?php

var_dump
(quotemeta('PHP is a popular scripting language. Fast, flexible, and pragmatic.'));
?>

El resultado del ejemplo sería:

string(69) "PHP is a popular scripting language\. Fast, flexible, and pragmatic\."

Notas

Nota: Esta función es segura binariamente.

Ver también

  • addslashes() - Añade barras invertidas en un string
  • addcslashes() - Añade barras invertidas a un string, al estilo del lenguaje C
  • htmlentities() - Convierte todos los caracteres elegibles en entidades HTML
  • htmlspecialchars() - Convierte caracteres especiales en entidades HTML
  • nl2br() - Inserta un salto de línea HTML en cada nueva línea
  • stripslashes() - Quita las barras de un string con comillas escapadas
  • stripcslashes() - Decodifica un string codificado con addcslashes
  • preg_quote() - Protección de caracteres especiales de expresiones regulares

add a note

User Contributed Notes 3 notes

up
16
kumarkulandai at gmail dot com
15 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
9
George Adams
19 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
6
Anonymous
24 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