Last active
August 29, 2015 14:12
-
-
Save codfish/874337ea4dc342249d66 to your computer and use it in GitHub Desktop.
This function strips incompatible iso characters from ms office documents. If no ascii conversion is found the character is ignored.
This file contains 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
/** | |
* This function strips incompatible iso characters | |
* from ms office documents. If no ascii conversion is found | |
* the character is ignored. | |
* | |
* @author hannuraina | |
* @param array|string $replace value(s) to replace | |
* @return array|string $items | |
*/ | |
function msword_to_ascii($replace) { | |
if (empty($replace)) { | |
return $replace; | |
} | |
// convert single values to array | |
$items = !is_array($replace) ? [$replace] : $replace; | |
array_walk($items, function(&$item, $key) { | |
if (is_string($item)) { | |
$value = @iconv('UTF-8', 'ASCII//TRANSLIT', trim($item)); | |
// word/excel generated characters will fail with | |
// default iconv implentation on linux. target | |
// windows input charset. | |
$item = $value ? $value : @iconv('Windows-1252', 'ASCII//TRANSLIT//IGNORE', trim($item)); | |
} | |
}); | |
// determine return type from original input | |
return is_array($replace) ? $items : reset($items); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment