PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

What is the usage of {} in strings?


The curly brackets or braces are used to clearly demarcate the variables that may be printed within the string.

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?



Custom Search