diff options
-rw-r--r-- | search.php | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -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) ."&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 '<dl>'; - echo " <dt><a href='".$url."'>$full)</a></dt>"; + echo " <dt><a href='".$url."'>$fname($fsect)</a></dt>"; echo " <dd>$desc</dd>"; echo '</dl>'; } |