file_get_contents sometimes does not work as expected with special characters.
Can you please try this workaround?
$source = mb_convert_encoding($source, 'HTML-ENTITIES', "UTF-8");
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
Using Laravel 5.7 here and I'm facing a weird issue: I'm uploading some .html files via the application that I'm building and I want to process those files later using DOMDocument.
The upload is pretty basic, I'm saving the file using:
$request->source_file->store('files');
But when I read the uploaded file later on I get this two weird characters at the beginning:
��<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
I'm retrieving the file like so:
Storage::get('files/' . $this->source_file');
Also tried with the following code, but got the same result:
$source = file_get_contents(storage_path() . '/app/files/' . $this->source_file);
Any idea how those characters get there?
I'm also uploading CSV files and there's no such issue there.
Thanks.
Please or to participate in this conversation.