我有一个填充了数字行的 txt 文件...我有一个代码,用户可以在其中过滤 txt 文件中的特定行
过滤代码:
<?php
$file = 'upload/filter.txt';
$searchfor = $_POST['search'];
$btn = $_POST['button'];
$sum = 0;
if($btn == 'search') {
//prevents the browser from parsing this as HTML.
header('Content-Type: text/plain');
// get the file contents, assuming the file to be readable (and exist)
$contents = file_get_contents($file);
// escape special characters in the query
$pattern = preg_quote($searchfor, '/');
// finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/m";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
echo "Found matches:\n";
echo implode("\n", $matches[0]);
}
else{
echo "No matches found";
}
}
?>
例如,过滤的结果现在将从文本文件的 1,000,000 行中产生 4 行
0100002291310106200140001020055460000000001000000072860103508104 0100002291320106200140001020055460000000005000000072860103508101 0100002291330106200140001020055460000000001000000072860103508102 0100002291340106200140001020055460000000005000000072860103508109
我需要一个仅选择特定列并使用 PHP 代码将它们添加在一起的代码...示例我只想添加第 1-10 列,因此从上面给出的行中结构将如下所示
结构:
0100002291
0100002291
0100002291
请帮忙