【问题标题】:php insert into javascript works under php5 but not php7php insert into javascript 在 php5 下工作,但在 php7 下不工作
【发布时间】:2018-10-30 01:53:05
【问题描述】:

这个 sn-p 在 php5.6 中有效,但在 php7 中无效。

mp3: <script language = "php"> echo "\"" . $MP3FILE . "\"";</script>

错误是: 未捕获的 SyntaxError:意外的令牌

该网站是: DNSpanishEnglish.php 它在php5.6下工作。 这是整个声明,仅供参考。

$(document).ready(function(){
  $("#jQ_jP").jPlayer( {
          ready: function () {
                  $(this).jPlayer("setMedia", {
                         mp3: <script language = "php"> echo "\"" . $MP3FILE . "\"";</script>
                // Defines the mp3 url
          });
         startingTime = 45;
         //endingTime = $(this).jPlayer("status", "duration");
         //myAlert( "  endingTime is " + endingTime);
                  $(this).jPlayer("play", 45);  // THIS WORKS!!!!!
                  //$(this).jPlayer("play").jPlayer("stop").jPlayer("playHead", ).jPlayer.status.currentTime);
                  //$(this).jPlayer("playHead", {time: 50});
                  //$(this).jPlayer("play" , { time: 45 }); // works (required for auto-play), but the time args doesnt work.
          //  $(this).jPlayer("playHeadTime" , { time: 45000 });
         $("#jQ_jP").bind($.jPlayer.event.play, function(event) {
                  // Add a listener to report the time play began
                  //myAlert("HELLO from jplayer_1" +
                         //"Play began at time = " +
                  //     event.jPlayer.status.currentTime
                                  //);  // OK, this is happening.
                  //$("#jQ_jP").playHead(50); //doesnt work.
                  $("#jQ_jP").playHeadTime(45000);
                        // milliseconds. doesnt work.
         });
         $("#jQ_jP").playHeadTime(5000); // doesnt work.
          } // End of "ready". No semicolon here!
 });
});

【问题讨论】:

  • 为什么是&lt;script language="php"&gt;?为什么不&lt;?php?或者更好,&lt;?=

标签: javascript php


【解决方案1】:

这将是由于较新版本的 PHP7 删除了这些标签支持。您可以使用标准标签代替它,例如 or 。 希望这会帮助你。

【讨论】:

  • 谢谢!这样可行。我从 2011 年开始给自己写了一张便条
【解决方案2】:

在 php 的其他地方定义你的变量,你可以在那个脚本中使用它。

PHP

$MP3FILE = <?php echo $MP3fileLink ?>

JS

$(document).ready(function(){
  $("#jQ_jP").jPlayer( {
          ready: function () {
                  $(this).jPlayer("setMedia", {
                         mp3: $MP3FILE 
                // Defines the mp3 url
          });
         startingTime = 45;
         //endingTime = $(this).jPlayer("status", "duration");
         //myAlert( "  endingTime is " + endingTime);
                  $(this).jPlayer("play", 45);  // THIS WORKS!!!!!
                  //$(this).jPlayer("play").jPlayer("stop").jPlayer("playHead", ).jPlayer.status.currentTime);
                  //$(this).jPlayer("playHead", {time: 50});
                  //$(this).jPlayer("play" , { time: 45 }); // works (required for auto-play), but the time args doesnt work.
          //  $(this).jPlayer("playHeadTime" , { time: 45000 });
         $("#jQ_jP").bind($.jPlayer.event.play, function(event) {
                  // Add a listener to report the time play began
                  //myAlert("HELLO from jplayer_1" +
                         //"Play began at time = " +
                  //     event.jPlayer.status.currentTime
                                  //);  // OK, this is happening.
                  //$("#jQ_jP").playHead(50); //doesnt work.
                  $("#jQ_jP").playHeadTime(45000);
                        // milliseconds. doesnt work.
         });
         $("#jQ_jP").playHeadTime(5000); // doesnt work.
          } // End of "ready". No semicolon here!
 });
});

【讨论】:

    猜你喜欢
    • 2016-09-18
    • 1970-01-01
    • 2018-05-16
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 2014-12-09
    • 1970-01-01
    • 2016-04-18
    相关资源
    最近更新 更多