I've been messing with this code all night long, and haven't been able to get it quite right, and am unsure of what to even search for.
Here's what I'm doing. I am using PHP to parse .ini files to an HTML table.
Here is what I am using in the html file:
<?php
$datas = parse_ini_string(file_get_contents( 'https://dl.dropboxusercontent.com/u/12345/test.ini' ), true);
?>
<table border="1" cellspacing="0" cellpadding="5">
<tbody>
<?php
foreach( $datas as $data ) {
?>
<tr>
<td rowspan="2"><?php echo htmlspecialchars( $data["name"] ); ?></td>
<td>Name</td>
<td>Points</td>
</tr>
<tr>
<td><?php echo htmlspecialchars( $data["Name"] ); ?></td>
<td><?php echo htmlspecialchars( $data["Points"] ); ?></td>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
What I would like to show up on the table is what is notated as "Section n" Below:
[Section 1]
Points=3
[Section 2]
Points=173
[Section 3]
Points=173
I am unclear on how to show "Section n" in the table, I would like it to take the following format:
Section number | Points
Section 1 | 3
Section 2 | 173
Section 3 | 173
Any help or pointers is greatly appreciated! Thank you so much!!
Here is code that works, you can use the key to get the section name.
<?php
$datas = parse_ini_string(file_get_contents( 'http://hastebin.com/raw/ikovafilib' ), true);
?>
<table border="1" cellspacing="0" cellpadding="5">
<tbody>
<?php
foreach( $datas as $section => $data ) {
?>
<tr>
<td rowspan="2"><?php echo htmlspecialchars( $data["name"] ); ?></td>
<td>Name</td>
<td>Points</td>
</tr>
<tr>
<td><?php echo htmlspecialchars( $section ); ?></td>
<td><?php echo htmlspecialchars( $data["Points"] ); ?></td>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
EDIT: In future, when you're dealing with an array that you don't know the output of, you can use print_r() function to debug what it outputs.
Ini parse_ini_file
section name is added as key.
Try using
<?php
foreach( $datas as $key => $data ) {
?>
<tr>
<td rowspan="2"><?php echo htmlspecialchars( $key ); ?></td>
<td>Points</td>
</tr>
<tr>
<td><?php echo htmlspecialchars( $key ); ?></td>
<td><?php echo htmlspecialchars( $data["Points"] ); ?></td>
</td>
</tr>
<?php
}
?>