GitHub 项目搜索 - 查找你想要的开源项目
<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><h1>GitHub 项目搜索</h1>
<form method='get'>
<label for='search'>项目:</label>
<input type='text' name='search' id='search' value='<?php echo isset($_GET['search']) ? htmlspecialchars($_GET['search']) : ''; ?>' placeholder='输入关键词搜索'>
<button type='submit'>搜索</button>
</form>
<div class='result'>
<?php
if(isset($_GET['search'])) {
$q = $_GET['search'];
$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);
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>
原文地址: https://www.cveoy.top/t/topic/mV0r 著作权归作者所有。请勿转载和采集!