Oihana PHP

formatQuotedString.php

Table of Contents

Functions

formatQuotedString()  : string
Formats a string value with proper escaping and wrapping using the specified quote style.

Functions

formatQuotedString()

Formats a string value with proper escaping and wrapping using the specified quote style.

formatQuotedString(string $value[, string $quoteStyle = 'single' ][, bool $compact = false ]) : string

This function escapes necessary characters and wraps the string with either single or double quotes, depending on the provided style. Double-quoted strings will have common control characters escaped as well.

Parameters
$value : string

The raw string to quote and escape.

$quoteStyle : string = 'single'

The style of quoting to use: 'single' or 'double'. Default is 'single'.

$compact : bool = false
Tags
example
echo formatQuotedString("Hello world");                    // 'Hello world'
echo formatQuotedString("Line\nBreak", 'double');         // "Line\nBreak"
echo formatQuotedString("She said: 'hi'");                // 'She said: \'hi\''
echo formatQuotedString("Use \\ backslash", 'double');    // "Use \\ backslash"
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
string

The quoted and escaped string.


        
On this page

Search results