5. A String literal different ways

  1. Single quoted
  2. Double quoted
  3. Nowdoc syntax
  4. Heredoc syntax

Single quoted & double quoted:

<?php
	
	echo 'They don\'t know how it\'s possible';
	echo "<pre>";
	
	$karim="student";
	$age = 20;
	echo 'karim is a $karim, he is $age years old';
	echo "<pre>";	
	echo "karim is a $karim, he is $age years old";

	// single quoted ' ' that is show only variable
	// double quoted " " that is show only value

?>

1.Nowdocs are to single-quoted strings.
2.Heredocs are to double-quoted strings.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nowdoc & heredoc</title>
</head>

<body>
<?php 
$name = "Ataur rahman";
$email = "ataur@gmail.com";
$mobile = "667688754";
$address = "Dhaka, Bangladesh";

echo <<< 'test'

<table width="403" border="1">
  <tr>
    <td width="162">Name</td>
    <td width="225">$name</td>
  </tr>
  <tr>
    <td>Email</td>
    <td>$email</td>
  </tr>
  <tr>
    <td>Mobile</td>
    <td>$mobile</td>
  </tr>
  <tr>
    <td>Address</td>
    <td>$address</td>
  </tr>
</table>

test;
?>
</body>
</html>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s