PHPBuilder - viewman



RSS Twitter
Snippets Html

viewman

by: Edwin Groothuis
|
January 20, 2002

Version: 1.0

Type: Full Script

Category: HTML

License: BSD License

Description: View unix man-pages with PHP



<?php
    //
    // $Id: viewman.php,v 1.1 2002/01/21 04:09:59 mavetju Exp $
    //
    // Viewman.php by Edwin Groothuis (edwin@mavetju.org)
    //
    // Viewman is developed to view man-pages in a webbroswer.
    //
    // How to use:
    // In a shell, do "man ls > /path/ls.man"
    // On your webpage, add this link: viewman.php?page=/path/ls
    //
    // That's all.
    //
    // See CONTACT and LICENCE on the status of this project and 
    // on how to contact me.
    //

    if ($page=="") {
	echo "No page specified.";
	exit;
    }

    $file=$page.".man";
    if (!file_exists($file)) {
	echo "Page not found.";
	exit;
    }

    $fd=fopen($file,"r");
    $line=fgets($fd,4096);
    $t=explode("\t",$line);
    $title="Man page for $t[0]";
    fclose($fd);

    echo "<html><head><title>$title</title></head><body>\n";

    echo "<pre>\n";


    $fd=fopen($file,"r");
    while (!feof($fd)) {
	$line=fgets($fd,4096);

	if (strstr($line,"\x8")) {
	    //
	    // replace _^H..._ 's by a bold _
	    //
	    $line=ereg_replace("(_\x8)+_","<b><u> </u></b>",$line);
	    //
	    // replace _^H(whatever) by an underlined (whatever)
	    //
	    $line=ereg_replace("_\x8(.)","<u>\\1</u>",$line);
	    //
	    // replace (whatever)^H(whatever) by a bold (whatever)
	    //
	    $line=ereg_replace("(.)(\x8.)+","<b>\\1</b>",$line);
	}

	echo $line;
    }

    echo "</pre></body></html>\n";

?>

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Edwin Groothuis

Comment:



Comment:

(Maximum characters: 1200). You have characters left.