(PHP,xampp) syntax error in every code I test - php

I get a " Parse error: syntax error, unexpected" error for whatever I print.
The error "Parse error: syntax error, unexpected '"test"' (T_CONSTANT_ENCAPSED_STRING) in C:\xampp\htdocs\firstfile\test.php on line 3"
The code I tested
<?php
 echo 'test';
 
?>
A basic code, but the error persist.
How to solve this problem?

Could it be that what you posted is not the actual file that is executed? Certainly that file is fine syntactically, so there must be some stupid mistake somewhere. I see that the faulty file is inside a folder firstfile. You are really sure this posted file is that file inside the folder?
What is especially outstanding here are the double quote chars in the error message which simply are not present in the file you posted.
When an error like this remains unchanged whatever you do, then typically you edit the wrong file.

Related

A weird PHP file in which any instruction is a syntax error

I have a Web application in PHP which when / (or something else) of it is opened in a browser displays the following error in the browser: Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in /var/www/n_environment.php on line 3. The file n_environment.php is loaded with require_once 'n_environment.php'; in index.php. And also from different places. It contains just comments, calls to define (unconditional or guarded by if (!defined) and two assignments of arrays of strings to variables.
I thought maybe it's (indirectly) in a class but not in a method, which indeed PHP prohibits for require_once, but apparently that's not the problem here. If I put anything else as the first instruction, e.g. echo or an assignment, a similar error (with a different offending token) results.
If I comment out everything in the file except the initial <?php, the error changes to unexpected end of file.
And if I also remove the <?php, what I get in the browser is the file content (block comment with code inside) with â instead of new lines.
What are the possible, most likely reasons for such behaviour? And how to fix it?

How do I get this PHP function to work with usort()?

I copied and pasted the piece of code below from http://php.net/manual/en/function.usort.php :
<?php
function cmp($a,$b)
{    
return strcmp($a["fruit"], $b["fruit"]);
}
$fruits[0]["fruit"] = "lemons";
$fruits[1]["fruit"] = "apples";
$fruits[2]["fruit"] = "grapes";
usort($fruits, "cmp");
while (list($key, $value) = each($fruits)) {
echo "\$fruits[$key]: " . $value["fruit"] . "\n";
}
?>
At first it gave some error about the $b variable. Now the new incessant error is:
Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\testsort.php on line 4
I'm thoroughly confused as to the problem here.
When I copied and pasted the code, some strange characters were part of it. These were invisible within notepad but revealed by VS Code IDE. Removing them allowed the code piece work.

Parse Error OptimizePress 2 WP

Parse error: syntax error, unexpected 'OptimizePress_Install'
(T_STRING) in
/home/investor/public_html/wp-content/themes/optimizepress/lib/admin/install.php
on line 1
Getting this annoying error when I click on "Activate Theme". How do I get around this? Code is below on pastebin
http://pastebin.com/GJkL64d1
First of all it needs a space between <?php and class so change it to <?php class
The second reason is it failing is because it is a 1 line script (all goes is on one line).
The first time it meets a comment the rest of the script is commented out.
You can fix this by
Download the file where is it not a strange one line.
Remove all comments
Beautify the php (make currect spaces)

PHP error on a line of code I don't understand

I have an error on this code:
code:
$sessionsAry[] .= array('SessionId'=>$row['SessionId'], 'Mark'=>$row['Mark']);
error:
Parse error: syntax error, unexpected T_VARIABLE in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 122
What does this error mean and where is the error on this particular code?
First, remove the '.'
$sessionsAry[] = array('SessionId'=>$row['SessionId'], 'Mark'=>$row['Mark']);
Now, if you're still getting the error, make sure that $sessionsAry is an array and that $row is an array too. Try:
var_dump($sessionsAry, $row);
Also, make sure that you haven't missed off a ';' on the line before.
On line 121 you definetly forgot to put a semicolon, that is #1 explanation for this error usually.
You don't need to write .= since $array[] add a new entry to $array. So, use simply =.
When you see a "Parse error" spit out by PHP, it usually means you forgot a character (;) or formatted an expression incorrectly (.= has an extra period) . Consider getting a new PHP IDE that can point the error before you run the code. It will drastically help speed up your ability to code in PHP.

T_STRING error on line that just says <?php

So I'm writing a script in codeigniter, and I get the following error message:
Parse error: syntax error, unexpected T_STRING in /home/globalar/public_html/givinghusband.com/system/application/controllers/sizes.php on line 1
the only problem: the only thing on that line is this:
<?php
So I'm quite mysterified as to what's going on here? Have I typed PHP wrong or what?
There could be a problem with your editor when it updated the file. I just had this problem and the editor removed all line breaks.
If you are uncertain try opening your php file in another editor or use the Cpanel file manager to take a peak.
Or you may have an unterminated quote or statement on some previous line without an ending semicolon (;) . Check all files that are included before this one.
a bare <?php in the file leads to a parse error in php (don't ask). Try adding a whitespace or a newline after it
Sorry.A bit late but might helpful for others.Just looked at your question.Just use
<?
?>
instead of :
<?php
?>
and remove whitespaces/line breaks between your php open tag and class name .It will resolve this conflict.Ta

Categories