Oihana PHP

escapeTomlString.php

Table of Contents

Functions

escapeTomlString()  : string
Escapes a value so it can be embedded in a TOML basic string.

Functions

escapeTomlString()

Escapes a value so it can be embedded in a TOML basic string.

escapeTomlString(string $value) : string

The returned value does not include the surrounding quotes. Backslashes and double quotes are escaped, and the control characters TOML forbids in a basic string are written as escape sequences: the ones with a shorthand (\b, \t, \n, \f, \r) use it, the others and DEL become \uXXXX.

Without this, a value holding a quote or a backslash — a password, typically — produces a document the TOML parser rejects, and the whole file becomes unreadable.

Parameters
$value : string

The raw value to escape.

Tags
see
https://toml.io/en/v1.0.0#string
example
use function oihana\files\toml\escapeTomlString;

echo escapeTomlString( 'pa"ss\word' ) ; // pa\"ss\\word
echo escapeTomlString( "two\nlines" ) ; // two\nlines
echo escapeTomlString( "\x01" ) ;       // \u0001
author

Marc Alcaraz (ekameleon)

since
1.7.0
Return values
string —

The escaped value, ready to be wrapped in double quotes.

On this page

Search results