|
HTML
Javascript
Flash Actionscript
PHP
mySQL
ASP
MS-SQL
Linux
Others
Ziwoo Board
Portfolio
About
|
 |
PHP |
| 작성 |
2011-11-09 14:46:19 추천: 61 조회: 3194 |
| 제목 |
XML 기본 예제 |
| 이름(ID) |
지우 (ziwoo)
|
|
 |
-- A.com/test.xml --
<?xml version="1.0" encoding="euc-kr"?>
<root>
<article>
<title>첫번째 글입니다.</title>
<writer>김길동</writer>
<regdate>2011.11.11</regdate>
<hit>45</hit>
</article>
<article>
<title>두번째 글입니다.</title>
<writer>최길동</writer>
<regdate>2011.11.08</regdate>
<hit>30</hit>
</article>
~~~
</root>
-- B.com/test.php --
<?
$xml_file = "http://A.com/test.xml";
$dom = domxml_open_file($xml_file);
$root = $dom->document_element();
$lines = $root->child_nodes();
foreach($lines as $lineNodes){
$cells = $lineNodes->child_nodes();
foreach($cells as $cellNodes){
$Records[][$cellNodes->tagname()] = iconv("utf-8","euc-kr",$cellNodes->get_content());
}
}
print_r($Records);
//결과
$Records[0]["title"] = "첫번째 글입니다."
$Records[0]["writer"] = "김길동"
$Records[0]["regdate"] = "2011.11.11"
$Records[0]["hit"] = "45"
$Records[1]["title"] = "두번째 글입니다."
$Records[1]["writer"] = "최길동"
$Records[1]["regdate"] = "2011.11.08"
$Records[1]["hit"] = "30"
~~~
?>
<html>
<table>
<?for($i=0;$i<count($Records);$i++){?>
<tr>
<td><?=$Records[$i]["title"]?></td>
<td><?=$Records[$i]["writer"]?></td>
<td><?=$Records[$i]["regdate"]?></td>
<td><?=$Records[$i]["hit"]?></td>
</tr>
<?}?>
</table>
</html>
|
 |
 |
 |
 |
|
|