Skip to content
Advertisement

How to escape a double quotes, inside a double quotes, inside a single quotes in PHP/Javascript?

So I have a PHP code that generates a portion of HTML/JavaScript code like below:

$link = '<a href="javascript:void(0);" 
         class="btn btn-read btn-flat" 
         onclick="showLoginLightBox(0,2);">Click Here</a>';

This works fine, but I want to replace the second parameter “2” with a text. So I have tried:

$link = '<a href="javascript:void(0);" 
         class="btn btn-read btn-flat" 
         onclick="showLoginLightBox(0,"active");">Click Here</a>';

This just gives me an error saying SyntaxError: invalid escape sequence

I have many combinations ' and " and others but nothing works. Can someone help me here?

Advertisement

Answer

In HTML you can use &quot; instead of " and &apos; instead of '

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement