Web/PHP

android string xml to html table

aucd29 2013. 9. 26. 21:50
stirng.xml 을 한번에 비교하기 위해서 만듬

<html>
<head>
<title></title>
<meta name='author' content='OBIGO'>
<meta name='keywords' content=''>
<meta http-equiv='Cache-Control' content='no-cache'>
<meta http-equiv='Pragma' content='no-cache'>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
</head>
<body>
<?php
function loadXml($data)
{
    $xml = simplexml_load_string(stripslashes($data));

    foreach($xml->children() as $value)
    {
        if($value->getName() == "string" && strlen($value) > 0)
        {
            foreach($value->attributes() as $index2 => $value2)
            {
                if($index2 == "name")
                {
                    $res["$value2"] = stripslashes($value);
                }
            }
        }
    }

    return $res;
}

foreach($_POST as $index => $value)
{
    if(substr($index, 0, 3) == "xml")
    {
        $arrData[] = loadXml($_POST["$index"]);
    }
}
?>
<table cellspacing='0' cellpadding='0' border='0' align='center'>
<?php

foreach($arrData[0] as $index => $value)
{
    echo "<tr><td>";
    echo $index;
    echo "</td><td>";
    echo $value;
    echo "</td>";

    for($i=1; $i<sizeof($arrData); ++$i)
    {
        echo "<td>";
        echo $arrData[$i]["$index"];
        echo "</td>";
    }

    echo "</tr>";
}
?>
</table>

</body>
</html>