我想读取文本文件并在PHP中读取然后拆分成数组并在另一个文本文件中显示数据。之后,我将此文件转换为格式,然后任何用户都可以下载转换后的CSV文件。我附上了File.txt
的文件
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6">
<h2>IRIS to ASB Conversion</h2>
<div class="panel panel-default">
<div class="panel-body">
Please Upload IRIS File <br/>
<br/> <br/>
<form action="convertfile1.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" > <br/><br/><input type="submit" class="btn btn-info " value="Generate ASB Format">
</form>
</div>
</div>
</div>
</body>
</html>
<?php
$file="iris.txt";
$fopen = fopen($file, 'r');
$fread = fread($fopen,filesize($file));
fclose($fopen);
$remove = "\n";
$split = explode($remove, $fread);
$array[] = null;
$tab = ",";
foreach ($split as $string)
{
$row = explode($tab, $string);
array_push($array,$row);
}
echo "<pre>";
print_r($array);
echo "</pre>";
?>
我的代码没有在数组中显示任何内容,它是空白的。如何使用PHP中的try-catch模式在数组中的不同行中获取数据?之后该文件将被任何用户转换并下载为.CSV文件。
请帮帮我。