How to output JavaScript with PHP

前端 未结 12 1570
无人及你
无人及你 2020-11-27 06:16

I am new to PHP. I need to output the following JavaScript with PHP. This is my code:





        
12条回答
  •  甜味超标
    2020-11-27 06:42

    The following solution should work quite well for what you are trying to do.

    1. The JavaScript block is placed very late in the document so you don't have to worry about elements not existing.

    2. You are setting a PHP variable at the top of the script and outputting just the value of the variable within the JavaScript block.

      This way, you don't have to worry about escaping double-quotes or HEREDOCS (which is the recommended method if you REALLY must go there).

      Javascript Embedding Example

提交回复
热议问题