summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordweller <dweller@cabin.digital>2024-02-26 18:40:07 +0200
committerdweller <dweller@cabin.digital>2024-02-26 18:40:07 +0200
commit8883e5ea3fd5b3992df41e011f83f23402c75b63 (patch)
tree46fd7c8b4378171cc8c88e97d1b8d85a8687d1fb
parentf1ae79dd64ce98bc4ca23bc66726f458dab11080 (diff)
fix search entry parsing, regex magic
Diffstat (limited to '')
-rw-r--r--search.php21
1 files changed, 13 insertions, 8 deletions
diff --git a/search.php b/search.php
index 784e614..5e3c5f4 100644
--- a/search.php
+++ b/search.php
@@ -73,7 +73,9 @@
. escapeshellarg($query), $lines, $ret);
if($ret === 0)
{
- preg_match('/\<td.*\>.+\((.+)\)\<\/td>/i', $lines[4], $sect);
+ /* TODO: maybe hardcoding a line isn't such a good idea, but I don't wanna regex the
+ * whole thing */
+ preg_match('/\<td.*\>.+\((.+)\)\<\/td>/iu', $lines[4], $sect);
$url = "$root/?query=". urlencode($query) ."&ampsection=". urlencode($sect[1])
."&action=lmmtfy";
@@ -112,19 +114,22 @@
foreach($lines as $line)
{
- $split = explode(") - ", $line);
- $full = $split[0];
- $desc = $split[1];
+ preg_match('/^((.+)(?:,.+)*)\(((.+)(?:,.+)*)\)\s?-\s?(.*)$/Uu', $line, $matches);
+ $fname = $matches[1];
+ $name = $matches[2];
+ $fsect = $matches[3];
+ $sect = $matches[4];
+ $desc = $matches[5];
- $split = explode("(", $full);
- $name = explode(",", $split[0])[0];
- $sect = strtolower(explode(",", $split[1])[0]);
+ $descl = strlen($desc);
+ if($descl > 320) $desc = substr($desc, 0, 320) . "...";
+ elseif($descl === 0) $desc = "No synopsis.";
$url = "$root/search.php?query=". urlencode($name) ."&section=". urlencode($sect)
."&action=man";
echo '<dl>';
- echo " <dt><a href='".$url."'>$full)</a></dt>";
+ echo " <dt><a href='".$url."'>$fname($fsect)</a></dt>";
echo " <dd>$desc</dd>";
echo '</dl>';
}