<?php
str strval ( mix $var );
where,
$var = Variable to be converted to STRING
$var may be any scalar type or
an object that implements the __toString method.
Cannot be used on arrays or on objects
that do not implement the __toString method.
The __toString method will be studied later.
?>
TYPE | STRING |
SINGLE QUOTED | ' STRING ' |
DOUBLE QUOTED | " STRING " |
HEREDOC SYNTAX | <<<EOT STRING of multiple lines EOT; |
NEWDOC SYNTAX | <<<'EOD' STRING of multiple lines EOD;" |
ed48 |
ESCAPED CHARACTER | MEANING |
\n | Linefeed (LF or 0x0A = 10 in ASCII) |
\r | Carriage return (CR or 0x0D = 13 in ASCII) |
\t | Horizontal tab HT or 0x09 = 9 in ASCII) |
\v | Vertical tab (VT or 0x0B = 11 in ASCII) (since PHP 5.2.5) |
\e | Escape (ESC or 0x1B = 27 in ASCII) (since PHP 5.4.4) |
\f | Form feed FF or 0x0C = 12 in ASCII) (since PHP 5.2.5) |
\\ | BACKSLASH |
\$ | DOLLAR SIGN |
\' | SINGLE-QUOTE |
\" | DOUBLE-QUOTE |
\[0-7]{1,3} |
The sequence of characters matching the regular expression is a
character in octal notation, which silently overflows to fit in a byte (e.g. "\400" === "\000") |
\x[0-9A-Fa-f]{1,2} | The sequence of characters matching the regular expression is a character in hexadecimal notation |
\u{[0-9A-Fa-f]+} |
The sequence of characters matching the regular expression is a
Unicode codepoint, which will be output to the string as that
codepoint's UTF-8 representation (added in PHP 7.0.0) |
ed48 |
<?php
$xyz = "STRING DELIMITED BY \"DOUBLE QUOTATION MARKS\"";
$str0 = 'STRING DELIMITED BY \'SINGLE QUOTATION MARKS\'';
$carÇ = 'STRING DELIMITED BY SINGLE "QUOTATION MARKS"';
$_alo = "STRING DELIMITED BY DOUBLE 'QUOTATION MARKS'";
$rquo = " » ";
$str01 = "1AnVXY234";
$str02 = "1234567";
// HEREDOC
$str03h = <<<EOD
Easy come, easy go.\n\r<br>
If you can’t beat them, join them.\n\r<br>
Life begins at forty.\n\r<br>
Two heads are better than one.
EOD;
$str04h = <<<EOT
In PHP there are TWO types
of variables:
INTERNAL, (predefined).
OF USER: (user-defined).
EOT;
// NOWDOC
$str03n = <<<'EOD'
Easy come, easy go.
If you can’t beat them, join them.
Life begins at forty.
Two heads are better than one.
EOD;
$str04n = <<<'EOT'
In PHP there are TWO types
of variables:<br>
INTERNAL, (predefined)<br>
and<br>
OF USER: (user-defined).
EOT;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo strval($carÇ) . '<br><br>' .
strval($_alo) . '<br><br>' . strval($rquo) .
'<br><br>' . strval($str01) . '<br><br>' .
strval($str02) . '<br><br>' . strval($str03h) .
'<br><br>' . strval($str04n) . '<br><br>';
?>
<?php
$vv02a = [ 'c' => 299792458, 'G' => 6.67428E-11 ];
var_dump(strval($vv02a));
echo '<br><br>';
$vv02b = [ 2, 8, 18, 32, 32, 18, 8 ];
var_dump(strval($vv02b));
echo '<br><br>';
$vv02c = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
var_dump(strval($vv02c));
echo '<br><br>';
$vv02d = M_E;
var_dump(strval($vv02d));
echo '<br><br>';
$vv02e = 1.6e-19;
var_dump(strval($vv02e));
echo '<br><br>';
$vv02f = null;
var_dump(strval($vv02f));
echo '<br><br>';
$vv02g = FALSE;
var_dump(strval($vv02g));
?>