Created
April 23, 2018 07:43
-
-
Save fujimaki-k/0ce67401e6617cebe631e874b570e140 to your computer and use it in GitHub Desktop.
Normalize string
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 | |
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