From 8883e5ea3fd5b3992df41e011f83f23402c75b63 Mon Sep 17 00:00:00 2001 From: dweller Date: Mon, 26 Feb 2024 18:40:07 +0200 Subject: fix search entry parsing, regex magic --- search.php | 21 +++++++++++++-------- 1 file 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>/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>/iu', $lines[4], $sect); $url = "$root/?query=". urlencode($query) ."&section=". 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) ."§ion=". urlencode($sect) ."&action=man"; echo '
'; - echo "
$full)
"; + echo "
$fname($fsect)
"; echo "
$desc
"; echo '
'; } -- cgit v1.2.3