Oihana PHP

unquote.php

Table of Contents

Functions

unquote()  : string
Strips a single layer of surrounding matching quote characters from a string.

Functions

unquote()

Strips a single layer of surrounding matching quote characters from a string.

unquote(string $value) : string

Recognised pairs (symmetric and asymmetric):

  • '…' single quotes
  • "…" double quotes
  • `…` backticks
  • «…» French guillemets
  • “…” English typographic double quotes
  • ‘…’ English typographic single quotes / apostrophe

No-op when:

  • the value is empty,
  • the value does not start AND end with a matching pair,
  • only one side is quoted ("foo, foo").

Only one layer is removed (""foo"" becomes "foo", not foo). No escape decoding is performed inside the value.

Parameters
$value : string

The string to unquote.

Tags
example
unquote('"hello"');   // 'hello'
unquote("'hello'");   // 'hello'
unquote('`hello`');   // 'hello'
unquote('«hello»');   // 'hello'
unquote('"hello');    // '"hello'   (no-op, unmatched)
unquote('""');         // ''
unquote('');           // ''
author

Marc Alcaraz

since
1.0.8
Return values
string

The unquoted string, or the original value if no matching pair is found.

On this page

Search results