$file = file('zong.txt'); usort($file, 'sortByLen'); $handle = fopen('zong2.txt', 'a'); foreach ($file as $v){ fwrite($handle, $v); } fclose($handle); function sortByLen($a, $b) { if (strlen($a) == strlen($b)) { return 0; } else { return (strlen($a)…