Dinho Moreno Posted November 26, 2011 Report Share Posted November 26, 2011 Tenho esta função e esta apresentando erro function getCalendar($vars){ global $database, $session; $time = time(); $today = date('j',$time); if(isset($vars['y'])){ $year = date("y", $time); if ( strpos( $vars[ 'y' ], array( '/', '.', '\\', '%' ) ) === false && strlen( $vars[ 'y' ] ) == 2 ) { $year = $vars[ 'y' ]; } }else{ $year = date("y", $time); } if(isset($vars['m'])){ $month = date("m", $time); if ( strpos( $vars[ 'm' ], array( '/', '.', '\\', '%' ) ) === false && strlen( $vars[ 'm' ] ) == 2 ) { $month = $vars[ 'm' ]; } }else{ $month = date("m", $time); } $cal_date = "&y= . $year . "&m=" . $month; // Rebuild Query String $query_str = NULL; if(strlen($_SERVER['QUERY_STRING])){ $parts = explode("&", $_SERVER['QUERY_STRING']); foreach($parts as $part){ $key = explode("=, $part); if($key[0] != "y" && $key[0] != "Y" && $key[0] != "m" && $key[0] != "M"){ $query_str .= $part . "&"; } } } $_SERVER['QUERY_STRING] = $query_str; $prev_month = "?" . $_SERVER['QUERY_STRING']; $prev_month .= 'y= . ($month-1 == 0 ? str_pad($year-1, 2, "0", STR_PAD_LEFT) : $year) . '&m=' . ($month-1 == 0 ? 12 : str_pad($month-1, 2, "0", STR_PAD_LEFT)); $next_month = NULL; if($month != date("m", $time)){ $next_month .= "?" . $_SERVER['QUERY_STRING]; $next_month .= 'y=' . ($month+1 == 13 ? str_pad($year+1, 2, "0", STR_PAD_LEFT) : $year) . '&m=' . ($month+1 == 13 ? "01" : str_pad($month+1, 2, "0", STR_PAD_LEFT)); } $prev_next = array('«'=>$prev_month, '»'=>$next_month); $date = str_pad($year, 4, "20", STR_PAD_LEFT); $dateyear = $date; $date = $date . $month; $query = "SELECT * FROM #__entries WHERE EXTRACT(YEAR FROM date)='" . $dateyear . "' AND EXTRACT(MONTH FROM date)='" . $month . "' AND access <= '$session->useraccess' ORDER BY date"; $month_data = $database->GetArray($query); $days = array(); foreach($month_data as $day){ $arr = explode("-", $day['date']); $arr2 = explode(":", $date['date']); $arr3 = explode(" ", $arr2[0]); $day_value = date("j", strtotime(0, 0, 0, $arr[1], $arr[2], $arr[0])); $days[$day_value] = array('past.php?year=' . $year . '&month=' . $month. '&day=' . $day_value . $cal_date, 'entry_day'); } if(isset($days[$today])){ array_push($days[$day_value], '<span style="font-weight: bold;">'.$today.'</span>'); }elseif($month == date("m", $time)){ $days[$today] = array(NULL, NULL, '<span style="font-weight: bold;">'.$today.'</span>'); } return $this->generateCalendar($year, $month, $days, 3, NULL, 0, $prev_next); }o erro retornado é: Parse error: syntax error, unexpected T_STRING in C:\wamp\www\Journalness_4.1_Full\includes\calendar.class.php on line 78Poderia ajuda a resolver com urgência? Quote Link to comment Share on other sites More sharing options...
0 ESerra Posted November 26, 2011 Report Share Posted November 26, 2011 Acabei de copiar/colar o teu script e exectutar a não retornou nenhum erro. Quote Link to comment Share on other sites More sharing options...
0 Dinho Moreno Posted November 29, 2011 Author Report Share Posted November 29, 2011 (edited) Acabei de copiar/colar o teu script e exectutar a não retornou nenhum erro.Estou utilizando a versão PHP 5.3.5 Wampserver: Esta retornando o erro acima. Estou começando com PHP e preciso de ajuda para entender esta linhaErro retornado: Warning: strtotime() expects at most 2 parameters, 6 given in C:\wamp\www\Journalness_4.1_Full\includes\calendar.class.php on line 78no campo do banco aparece a data : 2011-11-26 05:32:11. Obrigado pela ajuda Edited November 29, 2011 by Dinho Moreno Quote Link to comment Share on other sites More sharing options...
0 mJi Posted November 29, 2011 Report Share Posted November 29, 2011 Erro retornado: Warning: strtotime() expects at most 2 parameters, 6 given in C:\wamp\www\Journalness_4.1_Full\includes\calendar.class.php on line 78no campo do banco aparece a data : 2011-11-26 05:32:11. A função 'strtotime' requer, no máximo, 2 parâmetros (e no mínimo 1). Você passou 6 parâmetros.Você deve passar uma string com um formato de data válido. Quote Link to comment Share on other sites More sharing options...
0 Dinho Moreno Posted November 29, 2011 Author Report Share Posted November 29, 2011 Erro retornado: Warning: strtotime() expects at most 2 parameters, 6 given in C:\wamp\www\Journalness_4.1_Full\includes\calendar.class.php on line 78no campo do banco aparece a data : 2011-11-26 05:32:11. A função 'strtotime' requer, no máximo, 2 parâmetros (e no mínimo 1). Você passou 6 parâmetros.Você deve passar uma string com um formato de data válido.Qual função usar nesta rotina para passar os parametros (6)? Quote Link to comment Share on other sites More sharing options...
0 mJi Posted November 29, 2011 Report Share Posted November 29, 2011 O segundo parâmetro de date() deve ser um timestamp. Para conseguir o timestamp de uma data GMT, use gmmktime(). Quote Link to comment Share on other sites More sharing options...
0 Dinho Moreno Posted November 29, 2011 Author Report Share Posted November 29, 2011 O segundo parâmetro de date() deve ser um timestamp. Para conseguir o timestamp de uma data GMT, use gmmktime().a linha original era: $day_value = date("j", mktime(0, 0, 0, $arr[1], $arr[2], $arr[0]));mais apresenta erro string inesperada. tirando $arr[2], funciona bem. creio que $arr[2], retorna o ano e preciso desta informaçãocomo estou estudando php, não estou entendendo bem como utilizar mktime.poderia passar um exemplo, por favor. Quote Link to comment Share on other sites More sharing options...
0 mJi Posted November 30, 2011 Report Share Posted November 30, 2011 Prefira gmmktime() ao invés de mktime().Estas funções que retornam timestamp devem receber inteiros, que representam ano, dia, mes, etc...Provavelmente você conseguiu tais informações de uma string, através de um explode, ou alguma expressão regular.As informações presentes no array $arr são strings. O que você deve fazer é convertê-las para valores inteiros antes de submeter á função gmmktime().Tente utilizando casts.Nem vou postar exemplo, pois você acha vários na própria documentação da linguagem. Quote Link to comment Share on other sites More sharing options...
Question
Dinho Moreno
Tenho esta função e esta apresentando erro
function getCalendar($vars){
global $database, $session;
$time = time();
$today = date('j',$time);
if(isset($vars['y'])){
$year = date("y", $time);
if ( strpos( $vars[ 'y' ], array( '/', '.', '\\', '%' ) ) === false && strlen( $vars[ 'y' ] ) == 2 ) {
$year = $vars[ 'y' ];
}
}else{
$year = date("y", $time);
}
if(isset($vars['m'])){
$month = date("m", $time);
if ( strpos( $vars[ 'm' ], array( '/', '.', '\\', '%' ) ) === false && strlen( $vars[ 'm' ] ) == 2 ) {
$month = $vars[ 'm' ];
}
}else{
$month = date("m", $time);
}
$cal_date = "&y= . $year . "&m=" . $month;
// Rebuild Query String
$query_str = NULL;
if(strlen($_SERVER['QUERY_STRING])){
$parts = explode("&", $_SERVER['QUERY_STRING']);
foreach($parts as $part){
$key = explode("=, $part);
if($key[0] != "y" && $key[0] != "Y" && $key[0] != "m" && $key[0] != "M"){
$query_str .= $part . "&";
}
}
}
$_SERVER['QUERY_STRING] = $query_str;
$prev_month = "?" . $_SERVER['QUERY_STRING'];
$prev_month .= 'y= . ($month-1 == 0 ? str_pad($year-1, 2, "0", STR_PAD_LEFT) : $year) . '&m=' . ($month-1 == 0 ? 12 : str_pad($month-1, 2, "0", STR_PAD_LEFT));
$next_month = NULL;
if($month != date("m", $time)){
$next_month .= "?" . $_SERVER['QUERY_STRING];
$next_month .= 'y=' . ($month+1 == 13 ? str_pad($year+1, 2, "0", STR_PAD_LEFT) : $year) . '&m=' . ($month+1 == 13 ? "01" : str_pad($month+1, 2, "0", STR_PAD_LEFT));
}
$prev_next = array('«'=>$prev_month, '»'=>$next_month);
$date = str_pad($year, 4, "20", STR_PAD_LEFT);
$dateyear = $date;
$date = $date . $month;
$query = "SELECT * FROM #__entries WHERE EXTRACT(YEAR FROM date)='" . $dateyear . "' AND EXTRACT(MONTH FROM date)='" . $month . "' AND access <= '$session->useraccess' ORDER BY date";
$month_data = $database->GetArray($query);
$days = array();
foreach($month_data as $day){
$arr = explode("-", $day['date']);
$arr2 = explode(":", $date['date']);
$arr3 = explode(" ", $arr2[0]);
$day_value = date("j", strtotime(0, 0, 0, $arr[1], $arr[2], $arr[0]));
$days[$day_value] = array('past.php?year=' . $year . '&month=' . $month. '&day=' . $day_value . $cal_date, 'entry_day');
}
if(isset($days[$today])){
array_push($days[$day_value], '<span style="font-weight: bold;">'.$today.'</span>');
}elseif($month == date("m", $time)){
$days[$today] = array(NULL, NULL, '<span style="font-weight: bold;">'.$today.'</span>');
}
return $this->generateCalendar($year, $month, $days, 3, NULL, 0, $prev_next);
}
o erro retornado é: Parse error: syntax error, unexpected T_STRING in C:\wamp\www\Journalness_4.1_Full\includes\calendar.class.php on line 78
Poderia ajuda a resolver com urgência?
Link to comment
Share on other sites
7 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.