******************************* 纯属新手,练手作品~ ****************************** 不废话,上源码。。。。 成语查询。。。对高三党用处还是挺大的。。。。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<html>
<head>
<style type="text/css">
body{
background-color: #eee;
}
#header{
background-color: #fff;
max-width:420px;
margin:20px auto 20px auto;
text-align:center;
}
.item{
height:100px;
background-color: #ccc;
margin:20px auto 20px auto;
max-width:420px;
}
</style>
</head>
<body>
<div id="header">
<h3>请输入你要查询的成语</h3>
<form action= "<?php echo htmlspecialchars($\_SERVER\["PHP\_SELF"\]) ?>" method="get">
<input type="text" name="chengyu" />
<input type="submit" value="查询">
</form>
</div>
$doc = new DOMDocument();
if($_GET\["chengyu"\])
{
$text=$_GET\["chengyu"\];
}
else
{
$text="一心一意";
}
$doc->load("http://api.uihoo.com/chengyu/chengyu.http.php?key=".$text."&format=xml");
if($doc){
$idioms = $doc->getElementsByTagName( "item" );
foreach( $idioms as $idiom )
{
//将多个成语全部输出
switch ($idiom->nodeName)
{
case "item": $chengyu = $idiom->getElementsByTagName( "chengyu" )->item(0)->nodeValue;
Echo "<div class='item'>"."<h1>".$chengyu."<h1>"."</div>";
$pinyin = $idiom->getElementsByTagName( "pinyin" )->item(0)->nodeValue;
Echo "<div class='item'>"."拼音:".$pinyin."</div>";
$diangu = $idiom->getElementsByTagName( "diangu" )->item(0)->nodeValue;
Echo "<div class='item'>"."典故:".$diangu."</div>";
$chuchu = $idiom->getElementsByTagName( "chuchu" )->item(0)->nodeValue;
$chuchu = $idiom->getElementsByTagName( "chuchu" )->item(0)->nodeValue;
Echo "<div class='item'>"."出处:".$chuchu."</div>";
$lizi = $idiom->getElementsByTagName( "lizi" )->item(0)->nodeValue;
Echo "<div class='item'>"."例子:".$lizi."</div>";
break;
}
}
}
</body>
</html>