Parse error: syntax error, unexpected '$ folder' (T_VARIABLE) in

0

I'm having this error, I read that this message appears when an error occurs in a previous line of code, which is strange for me, it's happening in the first line of the file.

Parse error: syntax error, unexpected '$ folder' (T_VARIABLE) in

<?php
 $pasta = $_SERVER["DOCUMENT_ROOT"]."/arquivos/";

 if(is_dir($pasta))
 {
  $diretorio = dir($pasta);

  while($arquivo = $diretorio->read())
  {
   if(($arquivo != '.') && ($arquivo != '..'))
   {
    unlink($pasta.$arquivo);
    echo 'Arquivo '.$arquivo.' foi apagado com sucesso. <br />';
   }
  }

  $diretorio->close();
 }
 else
 {
  echo 'A pasta não existe.';
 }
?>
    
asked by anonymous 23.07.2018 / 20:05

2 answers

3

Your spaces are not spaces or tabs, which is inside the following (from the gray box below):

  •   

See:

  • The ASCII space value ("") is 32
  • The ASCII value of tab ("\ t") is 9
  • The ASCII value of this character you used as space is 8195

That is, although it looks like space it is not.

It's another character, but it's neither space nor tab, you're certainly using a text editor that does not write code, it's probably using Microsoft Word or WordPad or TextEdit of Mac OSX in "advanced document" mode

So PHP will not work and no other script type probably, so I recommend that you manually rewrite your code using an appropriate text editor like one of these:

23.07.2018 / 20:21
1

I just rewrote the code and it worked:

if(is_dir($pasta)){
    $diretorio = dir($pasta);
    while($arquivo=$diretorio->read()){
        if(($arquivo!='.')&&($arquivo!='..')){
            unlink($pasta.$arquivo);
            echo "Arquivo $arquivo foi apagado com sucesso.<br>";
        }
    }
    $diretorio->close();
}else{
    echo "A pasta não existe";
}

I think that's exactly what @GuilhermeNascimento said now in his response.

    
23.07.2018 / 20:22