Error: "unexpected T_STRING" in PHP [closed]

2

I took an internet function to calculate the difference between the dates. I created a class to make it easier, because I'm going to use this function in other screens.

PHP Version: 5.2. *

Code calling the class:

  include("funcoes/datahora.php");
  $datahora = new dataHora();

The error is this:

FollowmycodeinPHP:

<?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; } } ?>

Source Code

    
asked by anonymous 20.02.2014 / 13:46

2 answers

2

I uploaded it again and incredible as it may, it worked. I think at the time of transferring the file, it must have been damaged.

Thanks for the help!

    
20.02.2014 / 14:15
0

According to this response , problem is in the characters of line break that in windows is represented as \r\n and in linux only \n

  

I fixed it. Writing the code in Windows implied that \ r \ n   such as line break characters, which were not correctly interpreted   on my Linux hosting: I converted all \ r \ n to the UNIX standard   of character line break \ n and corrected the error.

    
20.02.2014 / 14:10