Use a backslash as such

"From time to \"time\"";

Backslashes are used in PHP to escape special characters within quotes. As PHP does not distinguish between strings and characters, you could also use this

'From time to "time"';

The difference between single and double quotes is that double quotes allows for string interpolation, meaning that you can reference variables inline in the string and their values will be evaluated in the string like such

$name = 'Chris';
$greeting = "Hello my name is $name"; //equals "Hello my name is Chris"

As per your last edit of your question I think the easiest thing you may be able to do that this point is to use a 'heredoc.' They aren't commonly used and honestly I wouldn't normally recommend it but if you want a fast way to get this wall of text in to a single string. The syntax can be found here: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc and here is an example:

$someVar = "hello";
$someOtherVar = "goodbye";
$heredoc = <<<term
This is a long line of text that include variables such as $someVar
and additionally some other variable $someOtherVar. It also supports having
'single quotes' and "double quotes" without terminating the string itself.
heredocs have additional functionality that most likely falls outside
the scope of what you aim to accomplish.
term;
Answer from MoarCodePlz on Stack Overflow
Top answer
1 of 7
98

Use a backslash as such

"From time to \"time\"";

Backslashes are used in PHP to escape special characters within quotes. As PHP does not distinguish between strings and characters, you could also use this

'From time to "time"';

The difference between single and double quotes is that double quotes allows for string interpolation, meaning that you can reference variables inline in the string and their values will be evaluated in the string like such

$name = 'Chris';
$greeting = "Hello my name is $name"; //equals "Hello my name is Chris"

As per your last edit of your question I think the easiest thing you may be able to do that this point is to use a 'heredoc.' They aren't commonly used and honestly I wouldn't normally recommend it but if you want a fast way to get this wall of text in to a single string. The syntax can be found here: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc and here is an example:

$someVar = "hello";
$someOtherVar = "goodbye";
$heredoc = <<<term
This is a long line of text that include variables such as $someVar
and additionally some other variable $someOtherVar. It also supports having
'single quotes' and "double quotes" without terminating the string itself.
heredocs have additional functionality that most likely falls outside
the scope of what you aim to accomplish.
term;
2 of 7
76

Use the addslashes function:

 $str = "Is your name O'Reilly?";

 // Outputs: Is your name O\'Reilly?
   echo addslashes($str);
🌐
PHP
php.net › manual › en › function.addslashes.php
PHP: addslashes - Manual
If all you want to do is quote a string as you would normally do in PHP (for example, when returning an Ajax result, inside a json string value, or when building a URL with args), don't use addslashes (you don't want both " and ' escaped at the same time). Instead, just use this function: <?php function Quote($Str) // Double-quoting only { $Str=str_replace('"','\"',$Str); return '"'.$Str.'"'; } // Quote ?> Modify this easily to get a single-quoting function.
Discussions

Best way to escape single quotes - PHP - SitePoint Forums | Web Development & Design Community
This apparently is the wrong way: $popupContent .= " "; Suggestions? More on sitepoint.com
🌐 sitepoint.com
0
September 1, 2016
Escape single quote in sql statement w/ php
Hello, I am using php / mysql to insert records into a table. I have an array of values (from a select statement) and i am looping through the array and running an insert statement. i am passing the value {$result[‘last’]} which contains a last name. When the last name has an apostrophe ... More on community.spiceworks.com
🌐 community.spiceworks.com
8
3
August 20, 2012
escaping - How do I escape PHP data to be used in Javascript? - Stack Overflow
I am writing some JavaScript code that uses a string rendered with PHP. How can I escape single quotes (and only single quotes) in my PHP string? $('#myEl... More on stackoverflow.com
🌐 stackoverflow.com
How do I escape single quotes in PDO query without pdo::quote?
Use bound parameters instead? $stm = $pdo->prepare('SELECT * FROM whatever WHERE some_col LIKE ?'); $like = "Don't%"; $stm->execute([$like]); foreach ($stm as $row) { // ... } More on reddit.com
🌐 r/PHP
14
0
April 10, 2015
🌐
W3Schools
w3schools.com › php › php_string_escape.asp
PHP - Escape Characters
In PHP, an escape character is a backslash \ followed by the character you want to insert. An example of an illegal character is a double quote inside a string that is surrounded by double quotes:
🌐
SitePoint
sitepoint.com › php
Best way to escape single quotes - PHP - SitePoint Forums | Web Development & Design Community
September 1, 2016 - This apparently is the wrong way: $popupContent .= " "; Suggestions?
🌐
Spiceworks
community.spiceworks.com › programming & development
Escape single quote in sql statement w/ php - Programming & Development - Spiceworks Community
August 20, 2012 - Hello, I am using php / mysql to insert records into a table. I have an array of values (from a select statement) and i am looping through the array and running an insert statement. i am passing the value {$result[‘last’]} which contains a last name. When the last name has an apostrophe ...
🌐
TinyMCE
tiny.cloud › blog › php-escape
How to work with PHP escape quotes and characters | TinyMCE
December 7, 2023 - This function returns a list of each instance of a single character, and allows you to replace that with an escaped character. Useful for finding and replacing multiple special characters at once. ... This function is more effective for handling content that could fit into the JSON key and value structure. It creates a JSON data structure out of the content, which avoids the errors found in PHP when escaping quotes altogether.
Find elsewhere
🌐
DEV Community
dev.to › morinoko › double-quotes-vs-single-quotes-in-php-2e5n
Double Quotes vs Single Quotes in PHP - DEV Community
October 25, 2018 - Surrounding text by quotes makes that text a string. You can use either single quotes (' ') or double quotes(" "), but there are some important differences, which I'll go over in this post.
🌐
BUSoft Technologies
busofttech.com › home › php escape quotes how to do it right?
PHP Escape Quotes: How to Do It Right | BUSoftTech
March 10, 2026 - When using single quotes (‘’) to create a string literal, the single quote character needs to be escaped using a backslash(\’). ... Double quoted strings: By using double quotes the PHP code is forced to evaluate the whole string. The main difference between double quotes and single quotes is that by using double quotes, you can include variables directly within the string.
🌐
TutorialsPoint
tutorialspoint.com › article › is-there-a-php-function-that-only-adds-slashes-to-double-quotes-not-single-quotes
Is there a PHP function that only adds slashes to double quotes NOT single quotes
March 15, 2026 - John's book is titled "PHP Basics" and costs $25 · Use str_replace() for simple double quote escaping, or addcslashes() when you need more control over which characters to escape.
🌐
PortSwigger
portswigger.net › web-security › all-labs
All labs | Web Security Academy
Mystery lab challenge Try solving a random lab with the title and description hidden. As you'll have no prior knowledge of the type of vulnerability that ...
🌐
A Wiki of Ice and Fire
awoiaf.westeros.org › index.php › Brienne_Tarth
Brienne Tarth - A Wiki of Ice and Fire
Later, they are ambushed by different outlaws on the Duskendale road near Maidenpool. Cleos is killed and Jaime tries to escape, dueling Brienne with Cleos's sword. Manacled and out of practice, Jaime is surprised to learn that Brienne is stronger than him.[12] Jaime cannot defeat Brienne, who holds his head underwater.
🌐
Oatllo
oatllo.com › php course › php – variables, data types, constants, and syntax basics › difference between single quotes and double quotes in php
PHP Quotes: Single vs Double Quotes Complete Guide
August 31, 2025 - Choose based on readability and intent. When to use? * Single quotes (' '): for constants, simple texts without variables and without escape sequences (e.g., 'OK', 'C:\path\file.txt').
🌐
Grammar.com
grammar.com › grammar-check
Free Grammar Check
Free grammar & spell checker by Grammar.com -- check it out...
🌐
W3Schools
w3schools.com › php › php_echo_print.asp
PHP Echo and Print Functions
When using single quotes, variables have to be inserted using the . operator, like this: $txt1 = "Learn PHP"; $txt2 = "W3Schools.com"; echo '<h2>' . $txt1 . '</h2>'; echo '<p>Study PHP at ' .
🌐
PHPBuilder
board.phpbuilder.com › d › 10396261-escape-single-quote
Escape single quote - PHPBuilder Forums
April 2, 2018 - Hi there: I have been trying to escape a single quote. I have read up so much on this and have gone to many websites. I was getting a syntax error when po...
🌐
Spiceworks
community.spiceworks.com › programming & development
Escape single quote in sql statement w/ php - #4 by jefffinley - Programming & Development - Spiceworks Community
August 20, 2012 - So i found a function to do this on arrays: // From @banel @ webmastertalkforums.com function addslashesextended(&$arr_r) { if(is_array($arr_r)) { foreach ($arr_r as &$val) is_array($val) ? addslashesextended($val):$val=addslashes($val); unset($val); } else $arr_r=addslashes($arr_r); return $arr_r; } Then i added $results = addslashesextended($results); to my existing function and it is working correctly now.
🌐
SitePoint
sitepoint.com › php
Escaping double and single quotes - PHP - SitePoint Forums | Web Development & Design Community
May 19, 2015 - Hi, Here’s what I have. foreach ($author_query as $author) { echo $author['name'].", "; } I am trying to add a href link to it, but I’m having issues with quotes. What’s the right way to do this? The code below doesn’t work because I already opened single quotes with a href, then tried to use it with person_id. foreach ($author_query as $author) { echo "".$author['name'].", ". ""; }