Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="ko">
- <head>
- <meta charset="UTF-8">
- <title>php-xml</title>
- </head>
- <body>
- <?php
- $db = new PDO("mysql:host=localhost;dbname=web;charset=utf8","root","");
- $db->query("truncate city");
- $xml = simplexml_load_file("./korea3.xml");
- $citylist = $xml->city;
- foreach($citylist as $city){
- $cityattr = $city->attributes();
- foreach($cityattr as $key=>$value){
- $$key = $value;
- }
- $info = addslashes($city->info);
- $area = $city->area;
- $population = $city->population;
- echo "<h1>{$id}){$name_ko}</h1>";
- echo "<h2>{$name_en}</h2>";
- echo "<h3>{$name_full}</h3>";
- echo "<p>{$area}</p>";
- echo "<p>{$population}</p>";
- echo "<p>{$info}</p><hr>";
- $sql = "insert into city set ";
- $sql .= "cityid='{$id}'";
- $sql .= ",name_ko='{$name_ko}'";
- $sql .= ",name_en='{$name_en}'";
- $sql .= ",name_full='{$name_full}'";
- $sql .= ",area='{$area}'";
- $sql .= ",population='{$population}'";
- $sql .= ",info='{$info}'";
- $db->query($sql);
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment