I want to get variables defined in php.ini file and below is the line to do that.
$settings = parse_ini_file("php.ini");
It gives error
PHP Parse error: syntax error, unexpected T_LOGICAL_AND in path/of/file on line 218
That line in php.ini is
; <? and ?> tags as PHP source which should be processed as such. It's been
I think this is due to word and. But this line is a comment. So why is it giving this error?
Edit : Removing and from line in php.ini file solved issue. I don't know why it was causing problem. I changed line to
; <? n ?> tags as PHP source which should be processed as such. It's been
You made something wrong, I guess you included the file somewhere.
<?php tags in comments (or wherever) will not start a code section in an ini file meaning that parse_ini_file() will never start a PHP parser.
Steps to reproduce:
test.ini:
;<?php and ?>
a=1
test.php:
<?php
var_dump(parse_ini_file('test.ini'));
Output:
array(1) {
'a' =>
string(1) "1"
}
You see it works like a charm.
The error is not in php.ini, but somewhere about line 218 of your source file.
I dont see any comment lines
add // at the start of line or put that text in /* comment goes here*/
these brackets!
Related
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: 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)
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.
See the following snippet:
<?php
die("----die----");
sfafsadffas
echo "foo";
echo "bar";
?>
The result is:
Parse error: parse error in test.php on line 6.
Which is a bit unexpected, I would have thought we should get ----die----.
Now see the following:
<?php
die("----die----");
echo "foo";
echo "bar";
sfafsadffas
?>
The result is:
----die----
What exactly is going on here?
The echo is indirectly effecting your program: besides printing to screen/browser the echo is doing flush to the output buffer which tries to print all the output that was "aggregated" so far. Since there's a syntax error before the flush it will be discovered at this point. You can reproduce the same error by doing:
<?php
die("----die----");
sfafsadffas
flush();
?>
But, if you'll flush the output buffer before the parser reaches the syntax error - the die will be executed.
<?php
die("----die----");
flush();
sfafsadffas
?>
will output ----die---- and then the parser will stop execution because it died and you won't reach the line that causes a syntax error.
The first thing PHP does when executing a file is to run a syntax check looking for obvious errors. This includes missing ; semicolons, mismatched braces {}, etc.
The first snippet fails this first test:
<?php
die("----die----");
sfafsadffas // <-- no semicolon between this line of code and the next,
// so you get a 'parse error' before the file even gets run
echo "foo";
echo "bar";
?>
The second snippet survives the syntax check because of a little "feature" of PHP: the parser counts ?> as a semicolon. So when you run:
<?php
die("----die----");
echo "foo";
echo "bar";
sfafsadffas
?>
The syntax check says "OK" and PHP proceeds to run the file. And the file would in fact be perfectly valid if sfafsadffas was defined sometime earlier in the file.
And then because of your die, the code never gets down to line 7.
The first fails, because the parser see's the invalid text and errors out.
The second may or may not fail depending on your PHP interpreter, it may not fail because the pre-processor (or parser) is ignoring extraneous data at the end of the file.
the sfafsadffas is considered as a constant here.
In example 1, put a semicolon after sfafsadffas and you are using a constant a normal way so it works.
In example 2, You do no need to have a semicolon separate last line of code see this
Example 1:
It should not execute. Because the coding will run line by line. The invalid text will stop remain executions. Finally nothing will execute and execution will be fail.
Example 2:
By the reason of line by line execution the both echo statements will execute ,but finally the execution status will be fail.
Throws Parse error
Parse error: syntax error, unexpected $end on line 7
Please check
http://writecodeonline.com/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