index.php:
<?php
if(isset($_GET['act'])){
if($_GET['act']=='tran'){
$word=isset($_POST['word'])?$_POST['word']:0;
if($word){
$xml=simplexml_load_file('dict.xml');
$res=$xml->xpath("//word[en='{$word}']");
if($res) {
$zh = $res[0]->cn;
$str = '中:'.$zh;
} else {
$str = '无记录';
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 101 Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<!-- Bootstrap -->
<link rel="stylesheet" href="bootstrap.min.css">
<style>.container{ max-width: 330px;margin: 0 auto;text-align:center}.btn{}</style>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="http://cdn.bootcss.com/html5shiv/3.7.0/html5shiv.min.js"></script>
<script src="http://cdn.bootcss.com/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container"><form action="?act=tran" method="post" class="form-signin" role="form">
<h1>请输入单词:</h1>
<p><input name='word' type="text" class="form-control" placeholder="Email address" required autofocus></p>
<div class="jumbotron"><?php echo isset($str)?$str:'';?></div>
<button class="btn btn-primary btn-block" type="submit">翻译</button>
</form>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="bootstrap.min.js"></script>
</body>
</html>
dict.xml:
<?xml version="1.0" encoding="UTF-8"?>
<dict>
<word>
<en>admin</en>
<cn>管理员</cn>
</word>
<word>
<en>user</en>
<cn>用户</cn>
</word>
<word><en>hello</en><cn/></word><word><en>happy</en><cn>高兴</cn></word></dict>
add.php:
<?php
if(isset($_POST['submit'])) {
//接收参数
$en = $_POST['en'];
$cn = $_POST['cn'];
//添加数据
$xml = simplexml_load_file('dict.xml');
$word = $xml->addChild('word');
$word->addChild('en',$en);
$word->addChild('cn',$cn);
$xml->asXML('dict.xml');
echo '<script>alert("添加成功");window.location.href="index.php";</script>';
}
?>
<!DOCTYPE html>
<html lang="zh-cn">
<!-- Mirrored from v3.bootcss.com/examples/signin/ by HTTrack Website Copier/3.x [XR&CO'2013], Sun, 26 Jan 2014 11:51:19 GMT -->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<style>.container{ max-width: 330px;margin: 0 auto;text-align:center}.btn{}</style>
<title>Signin Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<!-- Just for debugging purposes. Don't actually copy this line! -->
<!--[if lt IE 9]><script src="../../docs-assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="http://cdn.bootcss.com/html5shiv/3.7.0/html5shiv.min.js"></script>
<script src="http://cdn.bootcss.com/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<form class="form-signin" role="form" action="" method="post">
<h2 class="form-signin-heading">请输入单词</h2>
<input name="en" type="text" class="form-control" placeholder="英文" required autofocus></br>
<input name="cn" type="text" class="form-control" placeholder="解释" required></br>
<button name="submit" class="btn btn-lg btn-primary btn-block" type="submit">添加</button>
</form>
</div> <!-- /container -->
<script src="jquery.min.js"></script>
<script src="bootstrap.min.js"></script>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
</body>
<!-- Mirrored from v3.bootcss.com/examples/signin/ by HTTrack Website Copier/3.x [XR&CO'2013], Sun, 26 Jan 2014 11:51:19 GMT -->
</html>