如何根据str len-php对file.txt的行进行排序
我想根据字符串len对file.txt进行排序 示例文件.txt:如何根据str len-php对file.txt的行进行排序,php,Php,我想根据字符串len对file.txt进行排序 示例文件.txt: wew 12dde 12swsw 11 swsw a ofter排序文件sorted.txt: a 11 wew swsw 12dde 12swsw 这应该满足您的需要: <?php function lensort($a, $b) { return strlen($a) - strlen($b); } $path1 = '/root/oldfile.txt'; $path2 = '/root/newfile
wew
12dde
12swsw
11
swsw
a
ofter排序文件sorted.txt:
a
11
wew
swsw
12dde
12swsw
这应该满足您的需要:
<?php
function lensort($a, $b) {
return strlen($a) - strlen($b);
}
$path1 = '/root/oldfile.txt';
$path2 = '/root/newfile.txt';
file_put_contents($path2, usort(file($path1), 'lensort'));
这应该满足您的需要:
<?php
function lensort($a, $b) {
return strlen($a) - strlen($b);
}
$path1 = '/root/oldfile.txt';
$path2 = '/root/newfile.txt';
file_put_contents($path2, usort(file($path1), 'lensort'));
tanX,如何在第页回显此参数?tanX,如何在第页回显此参数?
<?php
function lensort($a, $b) {
return strlen($a) - strlen($b);
}
$path1 = '/root/oldfile.txt';
$path2 = '/root/newfile.txt';
file_put_contents($path2, usort(file($path1), 'lensort'));