http://phpmyanmar.com

Usage Of - Single Quote - And - Double Quote - With Strings In PHP
Posted By - Ko Ko - January 5, 2007

Summary :
How to use -single quote- and -double quote- with strings in PHP

Show Myanmar Version show-myanmar-font

Usage of 'single quotes' and 'double quotes' in Strings

In PHP, a string is simply a group of characters.

They can contain:-

  • letters
  • ASCII characters
  • numbers
  • other variables

When you assign a string to a variable (or) echo the string out to the browser, you have to mark the start and end of the string.

The ways of doing this are:

1. Single Quotes:
echo 'Hi there';

2. Double Quotes:
echo "Hi there";

The two methods looks similar but they are slightly different. Look at the following codes:-

<html>
<head>
<title>quotes</title>
</head>
<body>

<?php
$name = "Sally";
echo "My name is $name";
echo "<br>";
echo 'My name is $name';
?>

</body>
</html>

You will see that the output of above are different.

My name is Sally
My name is $name

In the first code line, a variable was put between a pair of double quote. Its value Sally was displayed by the browser

echo "My name is $name" = My name is Sally

In the next code line, a variable was put between a pair of single quote. Its value Sally was not displayed by the browser.

echo 'My name is $name' = My name is $name

Play around with single and double quotes with different strings and variables and observe the differences.


Posted as - [programming] [php]
0 comment            submit comments