<?php $file_path = 'example.txt'; $file_content = file_get_contents($file_path, NULL, NULL, 0, 1000); $encoding = mb_detect_encoding($file_content, 'UTF-8', true); if ($encoding === 'UTF-8') { echo "The file is encoded in UTF-8."; } else { echo "The file is not encoded in UTF-8."; } ?>