What is the usage of {} in strings?
For instance, where there is ambiguity as to how to interpret a string, we can use the {} to tell PHP exactly what we mean as follows.
Or if we want to print a variable and immediately follow it with more text, then we can use the {} to allow this.
Take a look at the difference between these two:
<?php
$mystring = "stand";
echo "$mystringup and be counted!";
//PHP Notice: Undefined variable: mystringup in C:\phptest\sample.php on line 5 and be counted!
echo "{$mystring}up and be counted!";
//prints: standup and be counted!
?>
Comment on this Question and Answer >>>
ASK A QUESTION
More strings PHP Questions
How do I find the length of a string in PHP?How do I convert characters to HTML entities using PHP?
How do I turn a string into an array?
How do I extract the values of variables from a string?
How do I remove space from the start of a PHP string?
