Skip to content

Instantly share code, notes, and snippets.

@davidsklar
davidsklar / fix-broken-utf-8.php
Created August 25, 2015 17:23
Fixing Broken UTF-8
<?php
function fixBrokenUTF8($contents) {
static $replacement = chr(0xEF) . chr(0xBF) . chr(0xBD);
$expectingNewChar = true;
$expectedLength = 0;
$expectedIndex = 0;
$i = 0;
$out = "";