[英]Sort alphabetically numbers in a row
我要感谢你的耐心等待。
最初我需要PHP或Javascript或jQuery的答案。
我有一个超过800行的.txt文件,每行有许多数字,例如:
01-54-32-06-02-28-50-67 - ......(+/- 32个数字)
32-50-02-04-16-21-17-11 - ......(+/- 38个数字)
......(+/- 800行)
正如你所看到的,每一行都有很多数字,用' - '分隔。 而且文件有很多行。 什么是荒谬的数额。
会将这些数字留在有序的行中吗? 例:
01-02-06-28-32-50-54-67 -...
02-04-11-16-17-21-32-50 -...
...
不想在数据库中注册(对于PHP),或者手动完成所有操作。 需要太长时间,也许我会老去解决这一切。 :)
是否有任何工具可以对.txt文件进行排序。 我在想什么,例如:
/ 01-54-32-06-02-28-50-67 -...
/ 02-50-02-04-16-21-17-11 -...
...
'/'将成为开始组织生产线的触发器。 我不知道我在胡说八道。
我设法找到了一个类似的工具。 这个工具它命令所有数字,将所有数字保留在同一行。 我不想要的。
http://www.textfixer.com/tools/alphabetical-order.php
页面的代码来自这里:
http://www.overset.com/2008/09/01/javascript-natural-sort-algorithm-with-unicode-support/
我需要一个答案。 即使它是'男人,也没有只有NASA来拯救你' ,我需要一个帮助。
非常感谢你。
此脚本将筛选文件中的每一行并对其进行排序。
如果文件非常大,这可能会消耗大量资源。
您可以使用MySQL数据库进行简单的逐行排序,而不是从文件中获取。
如果您需要任何帮助,请告诉我。
<?php
// Getting Data from a file 'data.txt' into $content variable
$content = file_get_contents('data.txt');
// $info - array for storing final info
$info = array();
// Putting all lines in $info - put / at the end of every line or change the delimeter from '/' to anything else
$info = explode('/', $content);
// Going through All lines one by one - Sorting it and putting it back on the array
foreach ($info as $key => $value) {
$number = explode('-', $value);
sort($number);
$info[$key] = implode('-', $number);
}
// Echo - Save to File
print_r($info); //Echo'ing result
file_put_contents('final.txt', implode("\n/",$info)); //Putting it into file
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.