Created
July 20, 2013 17:08
-
-
Save NKame/6045729 to your computer and use it in GitHub Desktop.
Récupère des bouts de document Word 2007 borké par MacOS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: text/xml; charset=ISO-8859-1'); | |
$text = file_get_contents('document.xml'); | |
$offset = 0; | |
while ($offset >= 0) { | |
$ord = ordutf8($text, $offset); | |
if($ord > 128) { | |
if($ord == 8217) { | |
echo "'"; | |
} else if ($ord == 333) { | |
echo "oe"; | |
} else { | |
echo uchr($ord >> 8) . uchr($ord & 0xFF); | |
} | |
} else { | |
echo chr($ord); | |
} | |
} | |
function uchr($ord) { | |
if($ord != 0 && $ord != 13) { | |
switch($ord) { | |
case 224: return 'à'; | |
case 231: return 'ç'; | |
case 232: return 'è'; | |
case 233: return 'é'; | |
case 25: return "'"; | |
default: | |
return chr($ord); | |
} | |
} | |
} | |
function ordutf8($string, &$offset) { | |
$code = ord(substr($string, $offset,1)); | |
if ($code >= 128) { //otherwise 0xxxxxxx | |
if ($code < 224) $bytesnumber = 2; //110xxxxx | |
else if ($code < 240) $bytesnumber = 3; //1110xxxx | |
else if ($code < 248) $bytesnumber = 4; //11110xxx | |
$codetemp = $code - 192 - ($bytesnumber > 2 ? 32 : 0) - ($bytesnumber > 3 ? 16 : 0); | |
for ($i = 2; $i <= $bytesnumber; $i++) { | |
$offset ++; | |
$code2 = ord(substr($string, $offset, 1)) - 128; //10xxxxxx | |
$codetemp = $codetemp*64 + $code2; | |
} | |
$code = $codetemp; | |
} | |
$offset += 1; | |
if ($offset >= strlen($string)) $offset = -1; | |
return $code; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment