PHP - syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
When you're working with strings in PHP you'll need to pay special attention to the formation, using "
or '
$string = 'Hello, world!';
$string = "Hello, world!";
Both of these are valid, the following is not:
$string = "Hello, world';
You must also note that '
inside of a literal started with "
will not end the string, and vice versa. So when you have a string which contains '
, it is generally best practice to use double quotation marks.
$string = "It's ok here";
Escaping the string is also an option
$string = 'It\'s ok here too';
More information on this can be found within the documentation
Unexpected PHP Parse error: (T_CONSTANT_ENCAPSED_STRING), after I moved to new server
This is one of most common parsing PHP errors, I have encountered it mostly due to version conflict.
The PHP version on new server may be different from old one. Most probably lower than old one. Upgrade/ Match PHP version on both servers to get rid of error.
Codeigniter 2.2 Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
The last statement in your index
method is missing a quote:
$this->load->view(reports/view', $data);
// /\HERE
That should be:
$this->load->view('reports/view', $data);
ATM, PHP is treating the declaration, and statements in the view
method as strings:
$data['reports'] = $this->reports_model->get_reports();
Is what you see, but PHP sees this as:
//string CONSTANT STRING...
'$data[' reports '] = $this->reports_model->get_reports();'
That's why I always say:
Syntax highlighting saves lives!
Remarks:
There are some other, un-related, issues in your code: your constructor echo
-es, methods containing exit
statements etc... I suspect this is for debugging only. Even so: look into using Xdebug.
Without wanting to do too much self-promoting see this code-review of mine, where I explain why methods should never call exit
or echo
things. If you want, you can post some code of yours on CR, and I'll be happy to take a look at it
Phpstan fails with Syntax error, unexpected T_STRING, expecting ';' in definition of function
I have no idea what happened here, but the code is completely wrong. It's supposed to be an array definition, not a function. From the source code at https://github.com/asm89/stack-cors/blob/master/src/Cors.php, the definition should be
private $defaultOptions = [
'allowedHeaders' => [],
'allowedMethods' => [],
'allowedOrigins' => [],
'allowedOriginsPatterns' => [],
'exposedHeaders' => [],
'maxAge' => 0,
'supportsCredentials' => false,
];
If this file is in the vendor folder, set it back to the original and do not change it. Anything in the vendor folder should be managed by the developers, since the next time you run composer update
and there's a new version, it will overwrite any changes you've made. If there's an issue with a library you've included or is part of the original package, contact the developers instead.
Parse error: syntax error, unexpected 'The' (T_STRING), expecting ',' or ';' in (FILE LOCATION) on line 17
This line appears to be messing things up:
echo "The value you entered is not a number. Please enter a numerical
value”;
Instead, use:
echo "The value you entered is not a number. Please enter a numerical value";
PHP- Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or '$' in
You must be using a version of PHP before 5.5. Per the manual:
Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error.
-http://php.net/manual/en/function.empty.php
The reason you are getting this is because anything single quotes is a string. Change it to:
if(!empty($email) and !empty($password))
and you should be good to go.
The issue and error message can be seen here, https://3v4l.org/EgfFb. I'd also recommend updating your PHP version because based on the error you are using <= 5.2.17.
Related Topics
In PHP, How to Generate a Big Pseudo-Random Number
How to Update Timezonedb in PHP (Updating Timezones Info)
Htaccess Rule to Parse PHP in HTML Files Not Working
How to Disable or Encrypt "View Source" for My Site
How to Convert an Integer to an Array in PHP
PHP $_Server['Remote_Addr'] Shows Ipv6
How to Get Http Url of File Uploaded to Ftp Server
How to Upload a File Using Jquery's $.Ajax Function with JSON and PHP
How to Apply Url Normalization Rules in PHP
Reply-To Address in PHP Contact Form
$_Post Empty on Utf-8 Characters
Saving a Product Custom Field and Displaying It in Cart Page
How to Handle Newlines in JavaScript? (From PHP)
Create Unique Poll/Vote/Survey in PHP
"Warning: MySQL_Query(): Supplied Argument Is Not a Valid MySQL-Link Resource"