PHP – String

A string in PHP is a combination of characters like “Welcome to our website”

A string can be defined in four different ways:

  1. single quoted
  2. double quoted
  3. heredoc syntax
  4. nowdoc syntax (since PHP 5.3.0)

single quoted string in PHP

This is the simplest way to define any string. If you add any PHP variables then it will display the variable name as it is. It will never display the value of the variable in single quoted string in PHP.


double quoted string in PHP

in double quoted string, we can also add the PHP variable and all PHP variables will be executed and displays the variable value.


heredoc string in PHP

The heredoc string starts with <<<, after this an identifier is provided. We can also include PHP variables inside the heredoc string and it will display the variable value.


nowdoc string in PHP

the nowdoc string is a single quoted string but the nowdoc string is defined similar to the heredoc string. In nowdoc string, we can’t execute the PHP variables instead in heredoc string we can easily execute the PHP variables.




Leave a Reply

Your email address will not be published.