-3

I place to the php line a large piece of html code with javascript inserts (with jQuery) in which $ symbols is present.

<?php
    $site = <<<SITE_CODE

                setTimeout(function(){$(g_utils._f().menu.current_id).trigger('click')}, g_utils.effects.animation(g_utils._f().animation.events.loading, 'delay2'));           

    SITE_CODE;

    echo $site;

?>

PHP takes this as a variable and produces an error.

Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in D:\site\index.php on line 328

Tell me how to get rid of this problem?

Zhihar
  • 995
  • 9
  • 30
  • 3
    you can do \$ to escape the character – hungrykoala Oct 13 '17 at 08:34
  • Of course it takes it as a php-variable, it is inside the `` tags without any quotes. Google for [php echo jquery](https://www.google.nl/search?q=php+echo+jquery) and you'll find what is wrong. – Michel Oct 13 '17 at 08:40

1 Answers1

2

If you single quote the EOL string it will not evaluate any variable:

    $site = 

    <<<'SITE_CODE'

                setTimeout(function(){$(g_utils._f().menu.current_id).trigger('click')}, g_utils.effects.animation(g_utils._f().animation.events.loading, 'delay2'));           

    SITE_CODE;
FcoRodr
  • 1,403
  • 5
  • 14
  • Francisco Rodríguez, did not work, the problem persisted :( if I delete strings with $ - everything works – Zhihar Oct 13 '17 at 08:46
  • Sorry, I though it was double quotes but it is single quotes, try it now. – FcoRodr Oct 13 '17 at 08:52
  • Francisco Rodríguez! Thank you! It's work!!! And if now I still need to embed a php code (vartiables etc) in the php string - are there any ways? $$ for example, or something else? – Zhihar Oct 13 '17 at 09:27