You can use single quotes or double quotes to make a string:
$hola = 'hola';
$hola = "hola";
And in both cases if you print the variable you will see the word hola
.
The problem is when you try to use single or double quotes within this type of strings. To do this, you will have to use the backslash \
just before the quote type, just like the type of quotes you used to open and close the variable.
Examples:
$cadena = "esto' es una \" prueba '\r";
$cadena2 = 'esto" es una \' prueba "';
echo $cadena; //Devolverá --> esto' es una " prueba '
echo $cadena2; //Devolverá --> esto" es una ' prueba "
You also have to keep in mind that when you use simple quotes to open and close a String the String will be considered as it is, that is, if for example you put \r
within the variable cadena2
of the example, you will not make a line break but you will print \r
within the String.
On the other hand, with the double quotes the content of the String will be evaluated. As shown in the example I added before, \r
performs a line break.
The only thing that single quotes evaluate is whether you use a backslash to "escape" a single quote or a backslash ( \'
or \
).