javascript - parsing html <script> via PHP isn't working completely - Stack Overflow

I find this very strange, must be something I'm doing wrong, but still...I'm working on a pa

I find this very strange, must be something I'm doing wrong, but still... I'm working on a page using PHP and TPL files. In my TPL file, there's a place in the footer for some extra lines if needed.

For instance, formchecking with Javascript.

so in PHP I did this:

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

the $foot variable is then parsed and the result in HTML is this:

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

So {loadEvents();} went missing.

Does anybody see what I'm missing here... I'm seriously not finding it. Did I forget to escape a character or something?

I find this very strange, must be something I'm doing wrong, but still... I'm working on a page using PHP and TPL files. In my TPL file, there's a place in the footer for some extra lines if needed.

For instance, formchecking with Javascript.

so in PHP I did this:

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

the $foot variable is then parsed and the result in HTML is this:

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

So {loadEvents();} went missing.

Does anybody see what I'm missing here... I'm seriously not finding it. Did I forget to escape a character or something?

Share Improve this question edited Dec 1, 2008 at 15:27 Tomalak 339k68 gold badges546 silver badges635 bronze badges asked Dec 1, 2008 at 14:53 VordrellerVordreller 2,53011 gold badges34 silver badges51 bronze badges 2
  • by TPL files do you mean Smarty? How is the $foot getting into the tpl file? – Tom Haigh Commented Dec 1, 2008 at 15:05
  • Maybe telling people that you use a template engine instead of letting them guess would have been a nice thing to do. – Tomalak Commented Dec 1, 2008 at 15:13
Add a ment  | 

4 Answers 4

Reset to default 8

Obviously the template engine you are using eats away the part in curly braces.

Try something like:

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

It looks like you're using a template engine like Smarty, which tries to parse anything it finds within braces.

This page from the smarty documentation explains how to make smarty ignore sections it would otherwise parse.

I believe with {} that PHP is expecting a variable within them. I haven't tested this, but try using single quote instead of double-quotes.

If you are using smarty you could use the {literal}.

literal

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745296242a4621160.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信