Originally Posted by
Eddies
From text file I want Create an associative array(with a key and data) I need the first three characters of each line read as the key and the rest of the line as the value or data.
https://ibb.co/mRZJcK - I want an output like this
https://ibb.co/dnaDBe - This the text file used
https://ibb.co/cRMnNU - instrutions
Here ya go Girl!
I expect you transfer the 50 mill tonight to my bank account.
Code:
<?php
$handle = fopen("input.txt", "r");
$result_array = array();
//generate Assoc array
if ($handle) {
while(!feof($handle)) {
$line = fgets($handle);
$key = substr($line, 0, 3);
$value = substr($line, 3, strLen($line));
$result_array[$key] = $value;
}
fclose($handle);
} else {
echo "error opening the file";
}
?>
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8">
<title>RSPS - HomeWork comunity</title>
</head>
<body>
<table>
<tr>
<td>KEY</td>
<td>DATA</td>
</tr>
<?php foreach($result_array as $key => $value) :?>
<tr>
<td><?php echo $key; ?></td>
<td><?php echo $value; ?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>
WHY AM I BLOCK FOR POSTING COMMENTS!
I CANNOT POST THIS AS REPLY, thus thee should make a thread!