GitHub 项目搜索工具 - 快速查找 GitHub 代码库
<!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 '<p>共搜索到 ' . $data->total_count . ' 个项目:</p>';
foreach ($data->items as $item) {
echo '<p><a href='' . $item->html_url . '' target='_blank'>' . $item->full_name . '</a></p>';
echo '<p>' . $item->description . '</p>';
echo '<hr>';
}
}
?>
</div>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/mVNJ 著作权归作者所有。请勿转载和采集!