Parsing html <script> via PHP does not work fully

I think this is very strange, I must be doing it wrong, but still ... I am working on a page using PHP and TPL files. My TPL file has space in the footer for some extra lines if necessary.

For example, formatting with Javascript.

so in PHP I did this:

$foot = "<script type=\"text/javascript\">if(document.getElementById){loadEvents();}</script>"; 

then the $ foot variable is processed, and the result in HTML is as follows:

 <script type="text/javascript">if(document.getElementById)</script> 

So {loadEvents();} gone.

Does anyone see what I am missing here ... I seriously cannot find it. Did I forget to escape the character or something else?

+3
source share
4 answers

Obviously, the pattern engine you use takes away the part in braces.

Try something like:

 $foot = "{literal}<script type=\"text/javascript\">if(document.getElementById){loadEvents();}</script>{/literal}"; 
+8
source

It looks like you are using a template engine such as Smarty, which is trying to parse everything it finds in curly braces.

This page from smarty documentation explains how to make smarty ignore sections that he otherwise parsed.

+2
source

I believe {} that PHP expects a variable inside them. I have not tested this, but I will try to use a single quote instead of double quotes.

+1
source

If you use smarty, you can use {literal}.

literal

+1
source

All Articles