たとえばtwitterのツイートの中のユーザIDをリンクにしたいとき
@hoge, @hogehoge があると、@hogeを置換するときに@hogehogeのほうも置換されちゃう
これを防ぐには、ユーザIDを抽出した後に文字数の大きい順番にソートする必要がある
このロジックは文字列置換・文字列探索の業務でちょくちょく必要になる
$ary = ['hogehoge', 'hoge', 'aiueo'];
usort($ary, 'lrsort');
function lrsort ($a, $b) {
$la = strlen($a);
$lb = strlen($b);
if ($la < $lb) return 1;
if ($la > $lb) return -1;
return 0;
}