Define string without single or double quote in PHP

phpPHP allows you to define variables / strings specially in your scripts.

The most commonly used methods for defining the variable in php are single quote

or double quote

However, there is a third way of defining the strings value in PHP too, which is not so commonly used, Its EOD.

EOD is used as in this example:

$string = <<<EOD

anything you want to add with single quote or double quote within the variable strings value “like this” or ‘this’.

It won’t matter how many lines you write unless you have this ending comment as in the next line.


So the strings value will begin with <<<EOD and will end with EOD;

This is specially useful when your variables value is going to have both single and double quotes in it and you don’t have the option to add backslash to them to escape them.

Leave a Reply

Your email address will not be published.