-4

Are there additional quotation marks in Php, and JavaScript besides "..." and '...' in the case I need to nest them?

(The Alt+Number would be useful)

For example a Php echo:

echo "
  onClick='changeImage('example.jpg');'
";

I know I could escape the quotation marks , but I am wondering if there are another "level" of them that can be nested.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rafael
  • 193
  • 1
  • 11
  • 2
    Possible duplicate of [Escape quotes in JavaScript](http://stackoverflow.com/questions/2004168/escape-quotes-in-javascript) – Hodrobond May 19 '17 at 21:24
  • No, there isn't - not for php anyway, but if you need it, you might need to restructure your approach - you can always escape them though – Qirel May 19 '17 at 21:26

1 Answers1

2

Javascript

You are in luck, in ES2015 specs, javascript now allows template literals using back ticks.

console.log(`hello "world!" I'm doing well :)`);

PHP

Use Nowdocs. Don't use Heredocs unless you want to evaluate php code inside the string. Note: someone already answered this, but I'll just reiterate to contain a whole solution.

echo <<<'STR'
`hello "world!" I'm doing well :)`
STR;

Don't use Heredocs

echo <<<STR
`hello "world!" I'm doing well :)`
STR;

Or

echo <<<"STR"
`hello "world!" I'm doing well :)`
STR;

Difference is the single quoted name. This is a Heredoc. It will evaluate PHP code denoted by ${expression} in your string.

Don't use back ticks

In PHP backticks will be evaluated as a shell command and return the output of said shell command.

EyuelDK
  • 3,029
  • 2
  • 19
  • 27