Since switching to PHP 5.5 from version 3.x, I have noticed that it is attempting to interpret my JavaScript comment within a script tag in a PHP include file

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.

Answer №1

After upgrading from PHP 3.x to PHP 5.5, a new php.ini file was most likely installed, possibly enabling the asp_tags setting.

It's important to note that the ASP style tag will be eliminated in PHP 7.0.0, so it's recommended to disable this configuration option for future compatibility.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

the art of displaying a fully populated php array

Looking for advice with this code: <?php $result_array1 = array(); $sql1 = "SELECT * FROM `test_thing`"; $result1 = mysql_query("$sql1") or die($sql1.mysql_error()); while($row1 = mysql_fetch_array($result1)) { $result_array1[] = $row1[&ap ...

vee-validate remains consistent in its language settings

Having trouble changing the error message in vee-validate, any suggestions on how to fix this? import VeeValidate from "vee-validate"; import hebrew from "vee-validate/dist/locale/he"; Vue.use(VeeValidate, { locale: "he", dictionary: { he: { me ...

Tips for passing a timestamp to a Postgresql DB using a Button in a Form instead of a traditional rails time_select box

I am currently developing a CAD App in Rails 4 with Ruby 2. The goal is to provide users with a button on the screen to log an on-scene time and clear scene time, especially since most users will be using touch screen computers. Instead of using the defaul ...

Inspect all checkboxes created by JavaScript

I'm attempting to develop a checkall checkbox that will automatically select all the checkboxes I've created using JavaScript. Firstly, I gather the number of rows and columns from the user and then use JavaScript to generate a table and insert ...

Creating a membership website with Paypal integration, seeking assistance as a beginner. Any guidance would be greatly appreciated

After discussing the integration of PayPal into my website for membership, I am now working on creating a membership site specifically for racing fans. This site will offer three different levels of memberships - free, gold, and premium. Users who sign up ...

Learn the steps to Toggle Javascript on window resize

Is there a way to toggle Javascript on and off when the window is resized? Currently, resizing the window causes the navigation bar to stick and remain visible above the content. <script> if ( $(window).width() <= 1200 ) { }else{ $('nav& ...

Discovering the selected href URL using JQuery or JavaScript

How can I detect the clicked href URL using JQuery when no ID is being used? For example, if I have a list of links where some redirect to new pages and others call javascript functions to expand a div. What approach should be taken in JQuery/Javascript ...

The Dropdownlist jQuery is having trouble retrieving the database value

Within my database, there is a column labeled Sequence that contains integer values. For the edit function in my application, I need to display this selected number within a jQuery dropdown list. When making an AJAX call, I provide the ProductId parameter ...

Adjusting the Transparency of the Background in a Pop-Up

I am experiencing an issue with my popup where I want the background to be transparent. However, when I set the opacity in CSS to 0.5 or less, the text also becomes transparent and very dark. How can I achieve a background with 50% opacity while keeping th ...

Despite encountering an error in my terminal, my web application is still functioning properly

My code for the page is showing an error, particularly on the home route where I attempted to link another compose page The error message reads as follows: Server started on port 3000 Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after t at new Node ...

Twilio REST API progressive calling

I'm really struggling to understand why my code isn't functioning properly, especially since Twilio's debugger isn't showing any errors. I am attempting to create Sequential dialing in a REST API using Twilio, where it should continue c ...

NodeJS API integration failure during ReactJs login attempt

Currently, I am tackling a small project on implementing user login functionality in ReactJs with Nodejs and Express-session. The issue I am facing is that my front end (React login page) isn't functioning properly. Below is the Fetch API code snippet ...

Identify the location of the mouse and activate a specific function based

Tracking the x-coordinate of the mouse is crucial in this scenario. When the mouse approaches a specific threshold (250px) towards the left edge of the window, it should trigger the function "openNav." The function should close when the mouse moves away fr ...

Executing a function enclosed in parenthesis does not yield any output

My code is supposed to print the sender's name followed by "adopted" and then the first mentioned user. const { Client } = require('discord.js', 'async', 'discord-message-handler'); const bot = new Client(); const cfg = ...

ControlOrbiter - limit panning motion

Is there a way to restrict the camera's panning movement within a scene? I've experimented with adjusting the pan method in orbitControls, but I'm not completely satisfied with the outcome. I am hoping for a more convenient and proper solut ...

Matching multiple optional variables using preg_match_all

Imagine this sentence: $str = "[1]a[2] a [2] a [3][3]"; I am interested in finding all the matches within the square brackets, which I can achieve using the pattern '\[(.*?)\]'. But additionally, I also want to capture any content betw ...

Custom Symfony2 form with a field that is not directly tied to an entity

I'm new to Symfony2 and trying to create a login form in a controller. Here's the code: public function showAction() { $admin = new Administrator(); $form = $this->createFormBuilder($admin)->setAction($this->generateUrl('admin ...

Solving complex promises in both serial and parallel fashion

My current function performs four tasks that must be executed in a specific sequence: - promise1 - promiseAfter1 // In parallel - promise2 - promiseAfter2 To ensure the promises are handled sequentially, I have structured two separate functions as follows ...

Input the incomplete dates into an associative array

What is the most efficient method to fill in missing dates in an array while maintaining the correct order? I have tried using array_slice() with no success, leading me to resort to multiple nested loops and array conversions. Any suggestions on a better ...

Having difficulty updating an angular variable within a callback function

Currently, I am utilizing the Google Maps directions service to determine the estimated travel time. this.mapsAPILoader.load().then(() => { const p1 = new google.maps.LatLng(50.926217, 5.342043); const p2 = new google.maps.LatLng(50.940525, 5.35362 ...