<style>
		body {
			font-family: Arial, sans-serif;
			text-align: center;
		}
		h1 {
			margin-top: 50px;
		}
		form {
			margin-top: 50px;
		}
		input[type=text] {
			padding: 10px;
			font-size: 16px;
			border-radius: 5px;
			border: none;
			box-shadow: 0 0 5px #ccc;
			width: 500px;
			max-width: 90%;
			margin-right: 10px;
		}
		input[type=submit], button[type=submit] {
			padding: 10px 20px;
			font-size: 16px;
			border-radius: 5px;
			border: none;
			background-color: #0077b5;
			color: #fff;
			cursor: pointer;
		}
		.result {
			margin-top: 50px;
			text-align: left;
			max-width: 90%;
			margin-left: auto;
			margin-right: auto;
		}
		.result a {
			color: #0077b5;
			text-decoration: none;
		}
		.result a:hover {
			text-decoration: underline;
		}
	</style>
<pre><code>&lt;h1&gt;Github项目搜索&lt;/h1&gt;
&lt;form method=&quot;get&quot;&gt;
	&lt;label for=&quot;search&quot;&gt;项目:&lt;/label&gt;
	&lt;input type=&quot;text&quot; name=&quot;search&quot; id=&quot;search&quot; value=&quot;&lt;?php echo isset($_GET['search']) ? htmlspecialchars($_GET['search']) : ''; ?&gt;&quot; placeholder=&quot;输入关键词搜索&quot;&gt;
	&lt;button type=&quot;submit&quot;&gt;搜索&lt;/button&gt;
&lt;/form&gt;
&lt;div class=&quot;result&quot;&gt;
	&lt;?php
		if(isset($_GET['search'])) {
			$q = $_GET['search'];
			$url = &quot;https://api.github.com/search/repositories?q=&quot;.urlencode($q);
			$options = array(
				'http' =&gt; array(
					'user_agent' =&gt; 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
				)
			);
			$context = stream_context_create($options);
			$result = file_get_contents($url, false, $context);
			$data = json_decode($result);

			echo &quot;&lt;p&gt;共搜索到 &quot; . $data-&gt;total_count . &quot; 个项目:&lt;/p&gt;&quot;;

			foreach ($data-&gt;items as $item) {
				echo &quot;&lt;p&gt;&lt;a href='&quot; . $item-&gt;html_url . &quot;' target='_blank'&gt;&quot; . $item-&gt;full_name . &quot;&lt;/a&gt;&lt;/p&gt;&quot;;
				echo &quot;&lt;p&gt;&quot; . $item-&gt;description . &quot;&lt;/p&gt;&quot;;
				echo &quot;&lt;hr&gt;&quot;;
			}
		}
	?&gt;
&lt;/div&gt;
</code></pre>
style		body 			font-family Arial sans-serif;			text-align center;				h1 			margin-top 50px;				form 			margin-top 50px;				inputtype=text 			padding 10px;			font-size 16px;			border-radius 5px;			bord

原文地址: https://www.cveoy.top/t/topic/bsBF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录