escaping quotation marks in php

escaping quotation marks in php  using -'php'

I am getting Parse error, i think its because of the quotation marks over "time". How can I make it treat as a whole string.

The problem is that I cant manually add \ before every quotation mark. This is the actual text I need to compare.

asked Sep 14, 2015 by FrancesGiven
0 votes

1 Answer

0 votes

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: and here is an example:

$someVar = "hello";
$someOtherVar = "goodbye";
$heredoc = <<
answered Sep 14, 2015 by KelKaufmann