Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm getting this error:
Parse error: syntax error, unexpected ']', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in your code on line 70
Line 70 is $message.
$random_keys=array_rand($lel,1);
$message[] = $lel[$random_keys[0]];
The whole code is here:
$message = array();
$lel = array(
'Are you sure its the new year?',
'And i thought i was dumb', 'its not new year yet',
'LOL its ${date}', '...', '.....', '...', 'WUT', '.......',
'Ya drunk bruh ?', 'You sure you are not drunk ? what is 1+1 then ?'
);
$random_keys=array_rand($lel,1);
$message[] = $lel[$random_keys[0]];
Can we do it like this?
$message[] = $lel[rand(1,11)];
It still gives:
Parse error: syntax error, unexpected ']', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
You are only picking one random key here:
$random_keys=array_rand($lel,1);
So you want to do this:
$random_key = array_rand($lel,1);
$message[] = $lel[$random_key];
Working example: http://3v4l.org/PHWD8
Though, since you're only picking one random key, and one random message, do you even need $message to be an array? I'd just do this:
$message = $lel[array_rand($lel)];
Working example: http://3v4l.org/jJKrG
As for your parse error, there's something we're not seeing in the code you posted. Perhaps it is some other surrounding code, or perhaps you modified the code before pasting here? In any event, you can see that your exact code does not produce a parse error: http://3v4l.org/Io1jc
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
i have this bunch of code:
$field_with_lengths = array('menu', 'position', 'visible');
foreach($field_with_lengths as $field_with_lenths => $maxlength){
if(strlen(trim(mysql_prep($_POST[$fieldname]))) => $maxlength){
$errors[] = $fieldname;}
i'm getting the folowing error:
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in C:\xampp\htdocs\vp\edit_info.php on line 22
wich is: if(strlen(trim(mysql_prep($_POST[$fieldname]))) => $maxlength){
i am not managing to find anything wrong on line 22
how can i fix that up?
It's >= (greater than or equal to) not => (equal to or greater than):
if(strlen(trim(mysql_prep($_POST[$fieldname]))) >= $maxlength){
if(strlen(trim(mysql_prep($_POST[$fieldname]))) >= $maxlength){
Equal sign must come after the bracket
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
**php program for reading filenames and filetypes from a dir.**
it shows the syntax error :
Parse error: syntax error, unexpected 'filename' (T_STRING) in C:\xampp\htdocs\php\dir.php on line 9
<?php
$dir="C:\xampp\htdocs\php\";
if(is_dir($dir))
{
if($dirref=opendir($dir))
{
while(($file=readdir($dirref))!==false)
{
echo "filename : $file : filetype: ".filetype($dir.$file)."\n";
}
closedir($dirref);
}
}
?>
It appears you've escaped the closing quotes on your $dir= statement. I don't use php in a Windows environment, so I don't know if you can convert all your \ to /, but if not, you'll want to escape all the \:
$dir="C:\\xampp\\htdocs\\php\\";
Or use single quotes, which disables escape sequences:
$dir='C:\xampp\htdocs\php\';
Parse errors often indicate that there is a syntax (or string in this case) error in your code, BEFORE the error actually reported by the parser.
The error is on your first line: $dir="C:\xampp\htdocs\php\";
The backslash escapes the quotes.
Escape the backslashes in your code to make it work, like so:
$dir="C:\\xampp\\htdocs\\php\\";
$dir="C:\xampp\htdocs\php\";
Just remove the last '\' and make it
$dir="C:\xampp\htdocs\php";
It will Work..!
Change this:
$dir="C:\xampp\htdocs\php\";
to
$dir="C:\\xampp\\htdocs\\php\\";
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Improve this question
I'm getting the following error:
Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\Ads\register.php on line 5
This is not the full code, but a part of it. Why is that error being thrown?
$fname = _POST['name[first]'];
$lname = _POST['name[last]'];
$email = _POST['email'];
$address1 = _POST['address[addr1]'];
$address2 = _POST['address[addr2]'];
$city = _POST['address[city]'];
$state = _POST['address[state]'];
$country = _POST['address[country]'];
$phno = _POST['number'];
$adtype = _POST['select'];
You're missing the $ in $_POST on all your lines. And your syntax for multi-dimensional arrays is incorrect.
$fname = $_POST['name']['first'];
When you have name="name[first]" in the HTML input element, PHP turns this into a nested array in $_POST, rather than using name[first] as the key.
Try this
$fname= $_POST['name']['first'];
When you see syntax error, unexpected '[' in C:\xampp\htdocs\Ads\register.php on line 5
You should always check your code on line 5, it has invalid syntax
In this case on line 5:
$fname = _POST['name[first]'];
this is a invalid syntax
should replace with:
$fname = $_POST['name']['first'];
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am getting the following error message. Can someone please help me.
Parse error: syntax error, unexpected T_LNUMBER, expecting ']' in /home/whilesto/public_html/includes/init.php on line 61
Following is the code from line 54 to 66
if ($setts['is_mod_rewrite'])
{
$valsArray = explode(",", $_REQUEST['rewrite_params']);
$valsCnt = 0;
$count_valsArray = count($valsArray);
while ($valsCnt < $count_valsArray)
{
$_REQUEST[$valsArray[$valsCnt 1]] = $valsArray[$valsCnt];
$_GET[$valsArray[$valsCnt 1]] = $valsArray[$valsCnt];
$_POST[$valsArray[$valsCnt 1]] = $valsArray[$valsCnt];
$valsCnt = 2;
}
}
The error lies not only in line 61 but also in lines 62 and 63. You have to remove the 1 from between $valsCount and ]:
$_REQUEST[$valsArray[$valsCnt]] = $valsArray[$valsCnt];
$_GET[$valsArray[$valsCnt]] = $valsArray[$valsCnt];
$_POST[$valsArray[$valsCnt]] = $valsArray[$valsCnt];
It also seems to me that you’ve written an endless while loop. You may consider changing line 64 to:
$valsCnt++;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
Here is my code inside of a function:
list(${$page}Records, ${$page}MetaData) = getRecords(array(
'tableName' => $page,
'where' => '', // load first record
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
Problem is, the very first line of it throws this error :
Parse error: syntax error, unexpected T_STRING, expecting ',' or ')' in /[edited]/includes/functions.php on line 10
I've tried a bunch of different ways of going about this but I don't know much about PHP. Anyone know what's going on here?
${$page}Records
This is not how you use variable variables. PHP has no idea what you mean with Records there.
Try this:
${$page.'Records'}
PHP will run the code inside the {} and use that string as a variable name.