Oihana PHP

betweenQuotes.php

Table of Contents

Functions

betweenQuotes()  : string
Wraps an expression in quotes or a custom character.

Functions

betweenQuotes()

Wraps an expression in quotes or a custom character.

betweenQuotes([mixed $expression = '' ][, string $char = "'" ][, bool $useQuotes = true ][, string $separator = ' ' ][, bool $trim = true ]) : string
  • Strings are wrapped directly.
  • Arrays are concatenated with the given separator, then wrapped.
  • Wrapping can be disabled with the $useQuotes flag.
Parameters
$expression : mixed = ''

The value to wrap (string, array, or any type convertible to string).

$char : string = "'"

The quote or character to wrap around the expression (default: single quote ').

$useQuotes : bool = true

Whether to wrap the expression (default: true).

$separator : string = ' '

Separator used to join array elements (default: ' ').

$trim : bool = true

Whether to trim existing $left/$right characters (default: true).

Tags
example
betweenQuotes('world');               // returns "'world'"
betweenQuotes(['foo', 'bar']);        // returns "'foo bar'"
betweenQuotes('data', '`');           // returns '`data`'
betweenQuotes('raw', "'", false);     // returns 'raw'
betweenQuotes(['a','b'], '"', true, ','); // returns '"a,b"'
since
1.0.6
author

Marc Alcaraz

Return values
string

The resulting wrapped expression.


        
On this page

Search results