Home
Recent Articles
Php (By Category)
Misc (1)
News (1)
String (1)
Resources (By Category)
Web (2)
Tutorials
Usage Of -single quote- And -double quote- With Strings In PHP
Show Myanmar Version show-myanmar-fontPrinter Friendly Page

Usage of 'single quotes' and 'double quotes' in Strings
By - Ko Ko - January 5, 2007 - 9:06 am

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.


(End of Article)

url = http://PhpMyanmar.com/pphp/article/171
Get results from [ 18 ] search engines in 'one click'
 
Install Myanmar Font
  • Download the font, (zawgyi-one) here.
  • See how to install the font here.
Feedback (In English please)
Bigger-Shoutbox
 
visited