Search code examples
phpjavascriptquotes

Quotes issue with php and javascript


I need help to fix syntax errors with this string:

<?php echo do_shortcode('[computer_tablet]<a href="URL" class="btn btn-blue" style="margin-left: 6px;" onclick="javascript:void window.open('URL','1372423739702','width=300,height=320,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=0,left=0,top=0');return false;">Words</a>[/computer_tablet]'); ?>

Thank you


Solution

  • You're using the same quotes as part of the parameter string as you are using to define the start and end of the string. Hence, when the code compiles, the string starts at "[computer..." and ends at "windows.open(". You need to use escape quotes - \' - whenever you use the same quotes that you start and end your string with.

    <?php echo do_shortcode('[computer_tablet]<a href="URL" class="btn btn-blue" style="margin-left: 6px;" onclick="javascript:void window.open(\'URL\',\'1372423739702\',\'width=300,height=320,toolbar=0,menubar=0‌​,location=0,status=1,scrollbars=1,resizable=0,left=0,top=0\');return false;">Words</a>[/computer_tablet]'); ?>
    

    Notice the backslash before each single quote?