I'm creating a script to create a json file, filled with data from database.  

I'm executing my script from console. Not using any kind of html. 

The problem is, when I open the file, all the special characters are showed with it's code instead of the actual character. 

e.g:

`sunt gre&#537;ite. V&#259; rug&#259;m s&#259;`

When I copy/pasted the string from my file HERE in stackoverflow text editor, the characters are visible, but inside my json file all i see is: 

`Argil&#259; //This is what I have in database and I need to write the accented word inside my json file.`

I already tried: 
`htmlspecialchars()`, `htmlspecialchars_decode()`, `htmlentities()`. 

my function: 

```
   public function writeToFile($fileName, $output, $mode) {      
      $writeFile = fopen( $fileName, $mode ) or die ("Unable to open file");
      fwrite( $writeFile, htmlentities($output, ENT_QUOTES, 'UTF-8') );
      fclose( $writeFile );

   }

```