<?php
function uniqueNoEmpty($array) {
return array_unique(array_filter($array, 'strlen'));
}
$original_string = 'one two three 喞 喝 four 刷囿 two 跏正 吁';
if (!preg_match_all('~(\p{Han}+)|(\S+)~u', $original_string, $out)) {
echo 'no qualifying strings';
} else {
$singleBytes = uniqueNoEmpty($out[2]) ?? [];
$multiBytes = array_reverse(uniqueNoEmpty($out[1]));
echo implode(' ', array_merge($singleBytes,$multiBytes));
}
- Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- one two three four 吁 跏正 刷囿 喝 喞
preferences:
146.9 ms | 407 KiB | 5 Q