Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Parse error: syntax error, unexpected T_IF, expecting ')'
What should I do?
$show_smileys = true;
$find = array(
'!\[h1\](.+)\[/h1\]!isU',
'!\[b\](.+)\[/b\]!isU',
'!\[i\](.+)\[/i\]!isU',
'!\[u\](.+)\[/u\]!isU',
'!\[strike\](.+)\[/strike\]!isU',
'!\[spoiler\](.+)\[/spoiler\]!isU',
'!\[url=(.*?)\](.*?)\[/url\]!is',
'!\[player\](.+)\[/player\]!isU',
'!\[quote=(.*)\]!siU',
'!\[/quote\]!si'
if ($show_smileys == true) {
,'#:p#is',
'#:eek:#is',
'#:rolleyes:#is',
'#;\)#is',
'#:o#is',
'#:D#is',
'#:\(#is',
'#:mad:#is',
'#:\)#is',
'#:cool:#is'
}
);
You can't include an if condition inside an array. Define the primary portion of your array like this:
$find = array(
'!\[h1\](.+)\[/h1\]!isU',
'!\[b\](.+)\[/b\]!isU',
'!\[i\](.+)\[/i\]!isU',
'!\[u\](.+)\[/u\]!isU',
'!\[strike\](.+)\[/strike\]!isU',
'!\[spoiler\](.+)\[/spoiler\]!isU',
'!\[url=(.*?)\](.*?)\[/url\]!is',
'!\[player\](.+)\[/player\]!isU',
'!\[quote=(.*)\]!siU',
'!\[/quote\]!si'
);
And then use a condition to merge the rest:
if ($show_smileys == true) {
$smiles = array(
'#:p#is',
'#:eek:#is',
'#:rolleyes:#is',
'#;\)#is',
'#:o#is',
'#:D#is',
'#:\(#is',
'#:mad:#is',
'#:\)#is',
'#:cool:#is'
);
$final = array_merge($find, $smiles);
}
You can't put if in the middle of an array, it can only be used where statements are allowed. Do it this way:
$find = array(
'!\[h1\](.+)\[/h1\]!isU',
'!\[b\](.+)\[/b\]!isU',
'!\[i\](.+)\[/i\]!isU',
'!\[u\](.+)\[/u\]!isU',
'!\[strike\](.+)\[/strike\]!isU',
'!\[spoiler\](.+)\[/spoiler\]!isU',
'!\[url=(.*?)\](.*?)\[/url\]!is',
'!\[player\](.+)\[/player\]!isU',
'!\[quote=(.*)\]!siU',
'!\[/quote\]!si'
);
$smileys = array(
'#:p#is',
'#:eek:#is',
'#:rolleyes:#is',
'#;\)#is',
'#:o#is',
'#:D#is',
'#:\(#is',
'#:mad:#is',
'#:\)#is',
'#:cool:#is'
);
if ($show_smileys) {
$find = array_merge($find, $smileys);
}
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Have been stuck with this little issue, when using key value arrays inside a class |I will get an error syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ']'
class hello{
public function name(){
$allnames = array("name"=>"mark" , "role" => "admin");
}
}
I have checked your code in my system there is no any error in your code
<?php
class hello{
public function name(){
$allnames = array("name"=>"mark" , "role" => "admin");
return $allnames;
}
}
$obj = new hello;
print_r($obj->name())
?>
Please check
You may try assign array as
$allnames = ["name"=>"mark" , "role" => "admin"];
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 a problem. I've created a class 'Game', and in this class I have an array named 'ShadowField'. This Field contains objects ('Fields'):
class Game extends Gameboard
{
public $ShadowField = array();
public $GameField = array();
public $Home = array();
function __construct($c,$h,$w,$m,$fc){
parent::__construct($c,$h,$w);
$counter = 1;
for($index_h=0; $index_h<11; $index_h++){
for($index_w=0; $index_w<11; $index_w++){
array_push($this->ShadowField, new Field(parent::$this, $m, "FF8000", ($h/11.1)*$index_h, ($w/11.15)*$index_w, true, $counter, $index_h, $index_w));
$counter++;
}
}
$PlayerRed = new PlayerHome($this, $m, "FF0000", 0);
}
}
Then, in my next class, I tried to use this array, but then I got an error:
for($i=0;$i<4;$i++){
parent::__construct($game,$m,$c,$game->ShadowField[$FieldID[$i]]->Top,ShadowField[$FieldID[$i]]->Left);
}
Error:
Parse error: syntax error, unexpected '[' in C:\XAMPP\xampp\htdocs\ot\madn\Game.class.php on line 63
I don't understand it because it's an array, and I am calling it like an array, so what is the problem?
The "FieldID" is an array, too:
class PlayerHome extends Field
{
public $Color;
public $Player;
public $FieldID = array();
function __construct(Game $game, $m, $c, $p){
switch($p){
case 0: array_push($FieldID,1,2,12,13);
case 1: array_push($FieldID,10,11,21,22);
case 2: array_push($FieldID,100,101,111,112);
case 3: array_push($FieldID,109,110,120,121);
default:echo "Player_$p existiert nicht, bitte eine SpielerID zwischen 0-3 wählen.";
}
for($i=0;$i<4;$i++){
parent::__construct($game,$m,$c,$game->ShadowField[$FieldID[$i]]->Top,ShadowField[$FieldID[$i]]->Left);
}
}
}
(p.s.: Sorry for bad english)
You use it correctly the first time:
$game->ShadowField[$FieldID[$i]]->Top
However the second time you call ShadowField by itself without referencing the object:
ShadowField[$FieldID[$i]]->Left
Replace the line in the loop with this (formatted for visibility):
parent::__construct($game,
$m,
$c,
$game->ShadowField[$FieldID[$i]]->Top,
$game->ShadowField[$FieldID[$i]]->Left);
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
Please i dont know how to remove this error on line 7 onto this $rest_url = “https://mydomain.com/rest-api/analytics/HTML/”.$login.”/”.$hash.”/”.$timestamp.”.do”;
$timestamp = round(microtime(true) * 1000);
$login = ‘username’;
$password = ‘password’;
$hash = md5(md5($password).$timestamp);
$rest_url = “https://mydomain.com/rest-api/analytics/HTML/”.$login.”/”.$hash.”/”.$timestamp.”.do”;
$post_data = array(
‘range’ => ‘LAST_7_DAYS’,
‘groupBy’ => ‘PLACEMENT’
);
/* Options of HTTP request; http key should be used when posting to https url */
$options = array(
‘http’ => array(
‘header’ => “Content-type: application/x-www-form-urlencoded\r\n”,
‘method’ => ‘POST’,
‘content’ => http_build_query($post_data)
)
);
/* Actual call to REST URL */
$context = stream_context_create($options);
$result = file_get_contents($rest_url, false, $context);
echo($result);
Your string starting and ending characters are incorrect.
You are using ‘ and “ ... replace them with ' and " to make your code valid.
since file_get_contents() is not reliable in remote connections,
You have to use CURL to overcome this http error.
For more info on curl_init read this
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
<?php
// configuration
require("../includes/config.php");
render("home_form.php", ["title" => "Log In"]);
?>
/**
* Renders template, passing in values.
*/
function render($template, $values = [])
{
// if template exists, render it
if (file_exists("../templates/$template"))
{
// extract variables into local scope
extract($values);
// render header
require("../templates/header.php");
// render template
require("../templates/$template");
// render footer
require("../templates/footer.php");
}
// else err
else
{
trigger_error("Invalid template: $template", E_USER_ERROR);
}
}
replace render("home_form.php", ["title" => "Log In"]);
with
render("home_form.php", array("title" => "Log In"));
and
$values = []
with
$values = array()
Which PHP version do you use?
Short array syntax is available since PHP 5.4.0: http://php.net/manual/en/migration54.new-features.php
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
[16-Aug-2013 01:38:56 America/Sao_Paulo] PHP Parse error: syntax error, unexpected '}' in /home/lineage/public_html/includes/templates/activate.php on line 21
Archive:
<?php
if (!isset($included) || !$included) exit();
if ($hash->validate($_GET['serial']))
if ($_handlerLoginServer->exec($_queryLogin['activateAccount'],array($_GET['serial'])) > 0) {
$account = $_handlerLoginServer->select($_queryLogin['accountSerial'],array($_GET['serial']));
if ($cookie->set("referral")) {
if (!$_handlerLoginServer->select($_queryLogin['checkIP'],array($_SERVER['REMOTE_ADDR'])))
$_handlerLoginServer->execute($_queryLogin['increaseReferral'],array($cookie->get("referral")));
$playerInfo = $_handlerLoginServer->select($_queryLogin['selectPlayer'],array($cookie->get("referral")));
if ($playerInfo[3] % 10 == 0) {
$balance->increase($playerInfo[1],$_config['referralReward']);
$log->add($log->format($_lang['log']['referralReward'],array($_config['referralReward'])),$playerInfo[1]);
}
}
$cookie->delete("referral");
}
$log->add($_lang['log']['activatedAccount'],$account[0]);
$_templatePage->replace("feedback",$_lang['success']['activateAccount']);
} else
$_templatePage->replace("feedback",$_lang['error']['activateAccount']);
} else
$_templatePage->replace("feedback",$_lang['error']['serialFormat']);
?>
On Line 4 and 8 you need to add an opening brace
change line 4
if ($hash->validate($_GET['serial']))
to
if ($hash->validate($_GET['serial'])) {
change line 8
if (!$_handlerLoginServer->select($_queryLogin['checkIP'],array($_SERVER['REMOTE_ADDR'])))
to
if (!$_handlerLoginServer->select($_queryLogin['checkIP'],array($_SERVER['REMOTE_ADDR']))) {
Go to line 4, and add an open squiggily bracket:
<?php
if (!isset($included) || !$included) exit();
if ($hash->validate($_GET['serial'])){