#native_company# #native_desc#
#native_cta#

1.11

By Che, Dong
on May 31, 2002

Version: 1.11

Type: Full Script

Category: HTML

License: GNU General Public License

Description: added option checker and color syntax

<?php
/**
 * phpMan is a web interface of Unix command 'man' and 'perldoc'.
 * This script makes it easier to read man pages which is lengthy
 * and require you to use 'more' or 'pg' filters.
 * Just try it if you feel hard to remember the command for page back
 * or need to dump man page into text/html format.
 *
 * $Id: phpMan.php,v 1.11 2002/05/31 13:54:51 chedong Exp $
 * Author: Che, Dong
 * [email protected]
 */

//global title
$PHP_MAN_TITLE = "phpMan: Unix Manual / Perldoc Web Interface";

//header
echo "<html>
<head>
<style type="text/css">
<!--
b {color:blue}
u {color:green}
//-->
</style>
<title>$PHP_MAN_TITLE</title>
</head>
<body>";


//option checker
if ($docType == "perldoc") {
	$check_man = "";
	$check_perldoc = " checked";
}
else {
	$check_man = " checked";
	$check_perldoc = "";
}

//add promter and recursive call
echo "<b>$PHP_MAN_TITLE</b>
<form action="$PHP_SELF">
Command:
<input type="text" size=20 name="parm" value="$parm">
<input type="radio" name="docType" value="man"$check_man>man
<input type="radio" name="docType" value="perldoc"$check_perldoc>perldoc
<input type=submit>
</form>";

echo "<hr /><br />";
echo "<pre>";

//remove unsecure commands
$semi = strpos($parm,";");
if ($semi > 1)
	$parm = substr($parm, 0, $semi);

if ( $docType == "perldoc" )
	exec("perldoc $parm",$lines,$rc);
else
	exec("man $parm",$lines,$rc);


$count = count($lines);
for ( $i = 1; $i <= $count; $i ++ ) {
	//highlighting attribute characters
	$patterns = array(
					"/</",  //html special char: '>' => '&lt;';
					"/>/",  //html special char: '<' => '&gt;';
					"/_".chr(8)."(.)".chr(8)."./",	// _^H?^H? => <b><u>?</u></b>
					"/_".chr(8)."(.)/",  //_^H? => <u>?</u>
					"/.".chr(8)."(.)/",  //?^H? => <b>?</b>
					"/<b>.</b>".chr(8)."(<b>.</b>)/", //duplicated: <b>?</b>^H<b>?</b> => <b>?</b>
					"/&lt<b>&</b>lt;/", //reverse &lt;^H&lt; => <b>&lt;</b>
					"/&gt<b>&</b>gt;/", //reverse &gt;^H&gt; => <b>&gt;</b>
					);
	$replace = array(
					"&lt;",
					"&gt;",
					"<b><u>1</u></b>",
					"<u>1</u>",
					"<b>1</b>",
					"1",
					"<b>&lt;</b>",
					"<b>&gt;</b>"
					);

	$lines[$i] = preg_replace($patterns, $replace, $lines[$i]);
	echo "$lines[$i] <br />";
}

//footer
echo "</pre>
<hr />
<br />
<a href="https://phpbuilder.com/snippet/detail.php?type=snippet&id=597">$Id: phpMan.php,v 1.11 2002/05/31 13:54:51 chedong Exp $</a>
</body>
</html>";
?>