从3升级到PHP 5.5之后.x,它似乎试图解析我的JavaScript注释(嵌入在一个PHP包含文件的脚本标签)

After upgrading to PHP 5.5 from 3.x, it seems to be trying to parse my JavaScript comment (embedded in a script tag in a PHP include file)

本文关键字:PHP 注释 一个 脚本 标签 文件 包含 JavaScript 之后 3升 我的      更新时间:2023-09-26

我在相当长的一段时间内没有使用PHP,但我曾经建立的第一个网站,我用PHP做的,我使用include的一切。直到网站主机更新了PHP,一切都工作了,现在没有选择恢复到旧版本的PHP。我只需要修复这个奇怪的错误引起的更新到5.5,其中似乎 php试图解析javascript。

所以我使用include来分隔<head>部分,并且包含脚本标签的PHP文件如下所示:

scripts.php

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="../js/nav.js"></script>
<script>
  .. snip ..
</script>
<script>
    var imgId = [
                "ip-product-1",
                "ip-product-2",
                "ip-product-3",
                "ip-product-4",
            ];
            var ImageCnt = 0;
            function IPnextImage(direction) 
            {
                    var i=1;
                    while(i<5)
                    {
                    document.getElementById("ip-product-" + i).style.opacity = "0"; 
                    document.getElementById("ip-product-" + i).style.pointerEvents = "none";
                    i++;
                    }
                // ImageCnt set to: ImageCnt plus (if direction is left)<-1>(else)<1> - in other words, for "left" subtract one from ImageCnt and for "right" add one to it, and then convert this to <%> to keep anything from escaping the maximum or minimum. 
                ImageCnt = (ImageCnt + (direction == "left" ? imgId.length-1 : 1)) % imgId.length;
                document.getElementById(imgId[ImageCnt]).style.opacity = "1";
                document.getElementById(imgId[ImageCnt]).style.pointerEvents = "auto";  
            }       
</script>

然后我只使用scripts.phpinclude来形成文档。

但是现在有一个错误:PHP Parse error: syntax error, unexpected '>' in /hermes/waloraweb089/b2700/as.agcomput/AGWebsite1.2/includes/scripts.php on line 73

第73行是:

ImageCnt = (ImageCnt + (direction == "left" ? imgId.length-1 : 1)) % imgId.length; 
// ImageCnt set to: ImageCnt plus (if direction is left)<-1>(else)<1> - in other 
// words, for "left" subtract one from ImageCnt and for "right" add one to it, 
// and then convert this to <%> to keep anything from escaping the maximum or minimum. 

在PHP 5.5中发生了什么,这是一个问题,而在PHP 3.x中工作?

当你从PHP 3升级。你很可能得到一个全新的PHP .ini文件,它可能已经启用了asp_tags设置。

还请注意,这个ASP样式标签将从PHP 7.0.0中删除,因此禁用此配置选项是一个安全的选择。