diff options
author | Philip Wittamore <philip@wittamore.com> | 2025-05-07 23:02:24 +0200 |
---|---|---|
committer | Philip Wittamore <philip@wittamore.com> | 2025-05-07 23:02:24 +0200 |
commit | d90aebe04f9db8233801b358c5074230ada466eb (patch) | |
tree | 1f8e5c53f1c1b473d1657496617344f894e85032 /search.php | |
parent | 462f75b7e0ba21a46f1498740b8840796381a6b1 (diff) | |
download | blog-d90aebe04f9db8233801b358c5074230ada466eb.tar.gz blog-d90aebe04f9db8233801b358c5074230ada466eb.tar.bz2 blog-d90aebe04f9db8233801b358c5074230ada466eb.zip |
added web files
Diffstat (limited to 'search.php')
-rw-r--r-- | search.php | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/search.php b/search.php new file mode 100644 index 0000000..72d65c4 --- /dev/null +++ b/search.php @@ -0,0 +1,93 @@ +<?php +$string = ""; +if (isset($_POST["s"])) { + $string = htmlspecialchars($_POST["s"]); +} +?> +<!doctype html> +<html> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <link rel="stylesheet" href="/style.css" /> + <link rel="icon" type="image/x-icon" href="/favicon.ico"> + <title>Bloggings</title> + </head> + <body> + <header> + <h1>Bloggings</h1> + <p><a href="index.php">Blog</a> | <a + href="sticky.php">Sticky</a> | <b>Search</b> | <a + href="https://wittamore-com.translate.goog/?_x_tr_sl=auto&_x_tr_tl=fr&_x_tr_hl=en-GB&_x_tr_pto=wapp">Français</a> | <a + href="https://git.wittamore.com" target="_blank" title="Git">Git</a> | <a + href="rss.xml">RSS</a> | <a + href="https://bsky.app/profile/wittamore.com" target="_blank">Bluesky</a></p> + <hr /> + </header> + <h2>Search this blog</h2> + <form action="search.php" method="post"> + <input name="s" type="text" autofocus> + <input type="submit"> + </form> + <!-- list start --> + +<?php if (!empty($string)) { + $string = strtolower($string); + echo "<h2>Results</h2>"; + echo 'Search terms: <b>"' . $string . '"</b>'; + echo "<h3>Static Pages</h3>"; + $dir = new RecursiveDirectoryIterator("./sticky"); + echo "<ul>"; + $i=0; + foreach (new RecursiveIteratorIterator($dir) as $filename => $file) { + if ($file != "." && $file != "..") { + if (!is_dir($file)) { + $content = strtolower(file_get_contents($file->getPathname())); + if (strpos($content, $string) !== false) { + $i++; + preg_match("/<h2>(.*?)<\/h2>/s", $content, $titre); + $title = "?"; + if (isset($titre[1])) { + $title = ucfirst($titre[1]); + } + echo '<li><a href="' . $file . '">' . $title . "</a></li>"; + } + } + } + } + if ($i == 0) echo "<i>No match</i>"; + echo "</ul>"; + echo "<h3>Articles</h3>"; + $dir = new RecursiveDirectoryIterator("./articles"); + echo "<ul>"; + $i=0; + foreach (new RecursiveIteratorIterator($dir) as $filename => $file) { + if ($file != "." && $file != "..") { + if (!is_dir($file)) { + $content = strtolower(file_get_contents($file->getPathname())); + if (strpos($content, $string) !== false) { + $i++; + preg_match("/<h2>(.*?)<\/h2>/s", $content, $titre); + $title = "?"; + if (isset($titre[1])) { + $title = ucfirst($titre[1]); + } + echo '<li><a href="' . $file . '">' . $title . "</a></li>"; + } + } + } + } + if ($i == 0) echo "<i>No match</i>"; + echo "</ul>"; +} ?> + + <!-- list end --> + <p> </p> + <hr /> + <p>§</p> + </body> +</html> + + + + |