<!DOCTYPE html>
<html>
<head>
	<title>Github项目搜索</title>
	<meta charset="utf-8">
	<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] {
			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>
</head>
<body>
	<h1>Github项目搜索</h1>
	<form action="#" method="get">
		<input type="text" name="q" placeholder="输入关键词搜索">
		<input type="submit" value="搜索">
	</form>
	<div class="result">
		<?php
			if(isset($_GET['q'])) {
				$q = $_GET['q'];
				$url = "https://api.github.com/search/repositories?q=".urlencode($q);
				$options = array(
					'http' => array(
						'user_agent' => '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);
<pre><code>			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>
</body>
</html>
html写一个github项目搜索

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

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