Oihana PHP

getQuoteChar.php

Table of Contents

Functions

getQuoteChar()  : string|null
Returns the opening quote character used to wrap a string, or `null`.

Functions

getQuoteChar()

Returns the opening quote character used to wrap a string, or `null`.

getQuoteChar(string $value) : string|null

Useful when you need to know which quote style was used in order to round-trip a value (unquote → transform → rewrap with the same style).

Recognised pairs:

  • '…' single quotes → returns "'"
  • "…" double quotes → returns '"'
  • `…` backticks → returns ''`
  • «…» French guillemets → returns '«'
  • “…” English typographic → returns '“'
  • ‘…’ English typographic → returns '‘'
Parameters
$value : string

The string to inspect.

Tags
example
getQuoteChar('"hello"'); // '"'
getQuoteChar("'hello'"); // "'"
getQuoteChar('«hello»'); // '«'
getQuoteChar('hello');   // null
getQuoteChar('"hello');  // null
getQuoteChar('"');        // null (too short)
author

Marc Alcaraz

since
1.0.8
see
isQuoted()
unquote()
Return values
string|null

The opening quote character, or null if the value is not wrapped in a known matching pair.

On this page

Search results