[DOC-CVS] [doc-en] master: Strings - Curly Brace Syntax: Add an escaping example; Improve runnable output with newlines (#5448)

[email protected] (AllenJB via GitHub) Fri, 3 Apr 2026 19:33:29 +0000
Newsgroups php.doc.cvs
Message-ID <[email protected]>
Author: AllenJB (AllenJB)
Committer: GitHub (web-flow)
Pusher: TimWolla
Date: 2026-04-03T21:33:26+02:00

Commit: https://github.com/php/doc-en/commit/ddc2a2d0966f746b67292b6c0987ef288747e409
Raw diff: https://github.com/php/doc-en/commit/ddc2a2d0966f746b67292b6c0987ef288747e409.diff

Strings - Curly Brace Syntax: Add an escaping example; Improve runnable output with newlines (#5448)

Changed paths:
  M  language/types/string.xml


Diff:

diff --git a/language/types/string.xml b/language/types/string.xml
index 147256930682..fcfb74084454 100644
--- a/language/types/string.xml
+++ b/language/types/string.xml
@@ -942,10 +942,13 @@ $arr = [
 ];
 
 // Won't work, outputs: This is { fantastic}
-echo "This is { $great}";
+echo "This is { $great}" . PHP_EOL;
 
 // Works, outputs: This is fantastic
-echo "This is {$great}";
+echo "This is {$great}" . PHP_EOL;
+
+// To show curly braces in the output:
+echo "This is {{$great}}" . PHP_EOL;
 
 class Square {
     public $width;
@@ -956,31 +959,31 @@ class Square {
 $square = new Square(5);
 
 // Works
-echo "This square is {$square->width}00 centimeters wide.";
+echo "This square is {$square->width}00 centimeters wide." . PHP_EOL;
 
 
 // Works, quoted keys only work using the curly brace syntax
-echo "This works: {$arr['key']}";
+echo "This works: {$arr['key']}" . PHP_EOL;
 
 
 // Works
-echo "This works: {$arr[3][2]}";
+echo "This works: {$arr[3][2]}" . PHP_EOL;
 
-echo "This works: {$arr[DATA_KEY]}";
+echo "This works: {$arr[DATA_KEY]}" . PHP_EOL;
 
 // When using multidimensional arrays, always use braces around arrays
 // when inside of strings
-echo "This works: {$arr['foo'][2]}";
+echo "This works: {$arr['foo'][2]}" . PHP_EOL;
 
-echo "This works: {$obj->values[3]->name}";
+echo "This works: {$obj->values[3]->name}" . PHP_EOL;
 
-echo "This works: {$obj->$staticProp}";
+echo "This works: {$obj->$staticProp}" . PHP_EOL;
 
 // Won't work, outputs: C:\directory\{fantastic}.txt
-echo "C:\directory\{$great}.txt";
+echo "C:\directory\{$great}.txt" . PHP_EOL;
 
 // Works, outputs: C:\directory\fantastic.txt
-echo "C:\\directory\\{$great}.txt";
+echo "C:\\directory\\{$great}.txt" . PHP_EOL;
 ?>
 ]]>
      </programlisting>