在我的$result
变量中,我有一个 5 行字符串:
0100014746510106200140001020061780000000041666670072860103508101 0100008030950106200270002020139450000000020000006663540105338500 0100004586400106200270002020206660000000003700000511890102603900 0100008204530106200270002020218320000000011666670014450101008906 0100015309660106200270002021023010000000019400001666460105319807
我怎么能substr()
在每一行...为了得到这个结果:
010001
010000
010000
010000
010001
只需要获取每行的前 6 列...请帮助...
PHP代码:
$file = 'upload/filter.txt';
$searchfor = $_POST['search'];
$filename = $_POST['filename'];
$btn = $_POST['button'];
if($btn == 'GENERATE' ) {
//prevents the browser from parsing this as HTML.
//header('Content-Type: text/plain');
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=".$filename.".txt ");
header("Content-Transfer-Encoding: binary ");
// 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)){
$result = implode("\n", $matches[0]);
echo $result;
}
else{
echo "No matches found";
}
}