第一次在虎林发源码

第一次在虎林发源码,心里有点小激动哈~~~~~~~~~~~
*******************************
纯属新手,练手作品~~~~~
******************************
不废话,上源码。。。。
成语查询。。。对高三党用处还是挺大的。。。。
<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>
        <?php
        	$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>
回复列表(13|隐藏机器人聊天)
添加新回复
回复需要登录