Page 1 of 1
Loading xml file using php 4.3
Posted: Mon Jul 13, 2009 11:11 am
by uxan
Hello,
I am trying to load an xml file and getting data from it with php 4.3 but it is not working , anyone can help to handle that problem.
Thanks
Re: Loading xml file using php 4.3
Posted: Mon Jul 13, 2009 2:56 pm
by Darhazer
TIP: Show the code you are trying to use, so we can see where are your mistakes.
I'm using PHP 5 and I hardly can help you, but I'm sure, if you post your code you will receive much more replies.
Re: Loading xml file using php 4.3
Posted: Tue Jul 14, 2009 3:29 am
by uxan
<?php
$data = array();
function add_person( $first, $middle, $last, $email )
{
global $data;
$data []= array(
'first' => $first,
'middle' => $middle,
'last' => $last,
'email' => $email
);
}
if ( $_FILES['file']['tmp_name'] )
{
$dom = domxml_open_file($_FILES['file']['tmp_name']);
$rows = $dom->get_elements_by_tagname( 'Row' );
$first_row = true;
foreach ($rows as $row)
{
if ( !$first_row )
{
$first = "";
$middle = "";
$last = "";
$email = "";
$index = 1;
$cells = $row->get_elements_by_tagname( 'Cell' );
foreach( $cells as $cell )
{
$ind = $cell->attributes( 'Index' );
if ( $ind != null ) $index = $ind;
if ( $index == 1 ) $first = $cell->node_value();
if ( $index == 2 ) $middle = $cell->node_value();
if ( $index == 3 ) $last = $cell->node_value();
if ( $index == 4 ) $email = $cell->node_value();
$index += 1;
}
add_person( $first, $middle, $last, $email );
}
$first_row = false;
}
}
?>
<html>
<body>
<table>
<tr>
<th>First</th>
<th>Middle</th>
<th>Last</th>
<th>Email</th>
</tr>
<?php
foreach( $data as $row )
{
echo "<tr>";
echo "<td>$row['first']</td>";
echo "<td>$row['middle']</td>";
echo "<td>$row['last']</td>";
echo "<td>$row['email']</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
The last part in html is just to display data from that xml file