Skip to content

Instantly share code, notes, and snippets.

@fujimaki-k
Created April 23, 2018 07:43
Show Gist options
  • Save fujimaki-k/0ce67401e6617cebe631e874b570e140 to your computer and use it in GitHub Desktop.
Save fujimaki-k/0ce67401e6617cebe631e874b570e140 to your computer and use it in GitHub Desktop.
Normalize string
<?php
namespace Karmia\Helper\Normalize;
/**
* Normalize values
*
* @author fujimaki-k
* @param array $array
* @return array
*/
function normalize ($values) {
$result = [];
$items = is_array($values) ? $values : [$values];
foreach ($items as $key => $value) {
$lines = [];
foreach (explode("\n", str_replace(["\r\n", "\r"], "\n", $value)) as $line) {
$lines[] = preg_replace('/\p{C}/u', '', $line);
}
$result[$key] = trim(\Normalizer::normalize(implode("\n", $lines), \Normalizer::NFKC));
}
return is_array($values) ? $result : $result[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment