Written on 14. October 2020 by Lennart Christensen

How to use apostrophe inside an PHP echo

How to use apostrophe in a PHP echo

In PHP, the escape character is the backslash (\). You can add this before special characters to ensure that these characters appear as letters.

Here are two ways you can make a php string that contains an apostrophe:
Here are two ways you can create a php string that contains apostrophes:

Med backslash (\) / With backslash (\):

echo 'Lennart\'s name with an apostrophe, like thi\'s';

Or you can also write like that:

echo "Lennart's name with an apostrophe, like thi's";

Hi, I'm Lennart. WordPress developer from Denmark. I write in Danish, but the piece of code itself is universal and can be understood outside Denmark as well 😀