After a long break from working with PHP, I recently encountered an issue with an older website I built using PHP and the include
function. The site was functioning perfectly until the web host updated PHP to version 5.5, causing a strange bug where it seems like PHP is trying to parse JavaScript code.
To address this problem, I decided to separate the <head>
section using the include
function. Here is the content of the file 'scripts.php' that contains the JavaScript script tags:
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>
Despite using include
to incorporate 'scripts.php' into the document, I encountered an error:
PHP Parse error: syntax error, unexpected '>' in /hermes/waloraweb089/b2700/as.agcomput/AGWebsite1.2/includes/scripts.php on line 73
The problematic code on line 73 reads as follows:
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.
I am puzzled by why this code snippet no longer works in PHP 5.5 when it used to function correctly in earlier versions like PHP 3.x.