2
I took a function from the Internet to calculate the difference between the dates. I created a class to facilitate, because I will use this function on other screens.
PHP version: 5.2.*
Code calling the class:
include("funcoes/datahora.php");
$datahora = new dataHora();
That is the mistake:
Follow my PHP code:
<?php // <-- O erro está aqui, na primeira linha!
class dataHora {
function data($data){
$data_atual = mktime();
list($ano,$mes,$dia) = explode("-",$data);
list($dia,$hora) = explode(" ",$dia);
list($hora,$min,$seg) = explode(":",$hora);
$data_banco = mktime($hora,$min,$seg,$mes,$dia,$ano);
$diferenca = $data_atual - $data_banco;
$minutos = $diferenca/60;
$horas = $diferenca/3600;
$dias = $diferenca/86400;
if($minutos < 1){
$diferenca = "há alguns segundos. Mais precisamente: ".$diferenca." segundos";
} elseif($minutos > 1 && $horas < 1) {
if(floor($minutos) == 1 or floor($horas) == 1){ $s = ''; } else { $s = 's'; }
$diferenca = "há ".floor($minutos)." minuto".$s;
} elseif($horas <= 24) {
if(floor($horas) == 1){ $s = ''; } else { $s = 's'; }
$diferenca = "há ".floor($horas)." hora".$s;
} elseif($dias <= 2){
$diferenca = "ontem";
} elseif($dias <= 7){
$diferenca = "há ".floor($dias)." dias";
} elseif($dias <= 8){
$diferenca = "há uma semana";
} else {
$diferenca = date("d/m/Y",$data_banco);
}
return $diferenca;
}
}
?>
Can post/highlight the error line and previous, It looks like an unzipped quote.
– rray
That’s right @lost, probably missing or left a string delimiter. However it is not in the code posted, because it has no syntax error.
– utluiz
Updated! @lost
– Leonardo
Does this code run on a linux server? the file was created in windows?
– rray
It was created in windows, and I’m not sure if it’s linux server, @lost
– Leonardo
Create a new file and put
phpinfo()
this will show the operating system.– rray
Leonardo, the mistake could be encoding, since the file has accents. Try using Notepad++ or some editor and convert it to UTF-8. Or even it may have been damaged in the transfer via FTP. Already tried sending again?
– utluiz
I think I know what it is, try using the tag
<?
at the beginning and tag?>
in the end, instead of<?php
at the beginning and?>
at the end, to see if the error goes away.– Paulo Roberto Rosa
@lost. Yes, it’s Linux!
– Leonardo
I couldn’t reproduce your mistake, here in my machine worked perfectly.
– Guilherme
What @utluiz suggested worked, kkkk. I uploaded again and it worked perfectly, I think at the time of transferring, must have damaged the file. Thanks !
– Leonardo