CodesJava

Easy learning with example program codes

PHP Strings


A sequence of characters is called as string. In PHP, a string can be specified in four ways:

  • single quoted string
  • double quoted string
  • heredoc syntax string
  • newdoc syntax string

Single Quoted String:

A string enclosed in a single quote is called a single quoted string. Escape sequences and variables can not be interpreted using single quoted strings.

Double Quoted String:

A string enclosed in a double quote is called a double quoted string. Escape sequences and variables can be interpreted using double quoted strings.
Example 1: Variables inside a Single quoted string

<!DOCTYPE html>
<html>
<body>
 
<?php  
$num=100;   
$string='print $num';  
echo "$string <br/>";  
?>
 
</body>
</html>

Output

print $num

Example 2: Variables inside a Double quoted string

<!DOCTYPE html>
<html>
<body>
 
<?php  
$num=100;   
$string="print $num";  
echo "$string <br/>";  
?>
 
</body>
</html>

Output

print 100
Posted in PHP   
Sign Up/ Sign In
Ask a Question


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki