Moonbat
03-28-2008, 06:17 PM
Well, after some work with formatting, I'm now able to release v0.* of this little script. All you do is enter your PHP code into the box, and it'll find many of the keywords that PHP uses, mostly functions, and link them to PHP.net's function reference. Like I've said before, this is just for fun; it's not meant to be that useful, but I've seen this kind of thing implemented on other sites (that don't release their code). So if you want to have something like this on your site, feel free to use it, but don't alter the comments.
<?php
/* PHP Keyword Parser v0.* */
/* Coded By Moonbat (with help from coz) */
echo <<< HTMLONE
<html>
<head>
<title>PHP Keyword Parser v0.*</title>
<style type="text/css">
textarea
{
background: black;
color: #FFFFFF;
}
a:link
{
color: #FFFFFF;
font-weight: bold;
}
a:visited
{
color: #FFFFFF;
font-weight: bold;
}
pre
{
color: white;
background: #444;
display: block;
margin: 0 *0px *2px;
overflow: auto;
padding: 8px *0px
}
</style>
</head>
<body bgcolor="666666">
HTMLONE;
if (isset($_POST['thephpcode'])){
$thephpcode = $_POST['thephpcode'];
$thekeywords = array("echo", "print", "fsockopen", "htmlentities",
"exit", "fputs", "fgets", "mysql_pconnect", "mysql_select_db", "nl2br", "flush", "explode",
"str_replace", "array", "chr", "rand", "mysql_query", "mysql_fetch_array", "file_get_contents",
"preg_match", "substr_replace", "str_replace", "set_time_limit", "isset", "fopen", "trim", "eregi",
"die", "microtime", "fwrite", "error_reporting", "strlen", "preg_replace", "file", "addslashes",
"get_magic_quotes_gpc", "md5", "setcookie", "time", "getdate", "sizeof", "strpos", "count",
"phpinfo", "ereg", "exec", "opendir", "is_dir", "mail", "sha*");
$thelinkarrays = array("<a href='http://www.php.net/echo'>echo</a>", "<a href='http://www.php.net/print'>print</a>",
"<a href='http://www.php.net/fsockopen'>fsockopen</a>", "<a href='http://www.php.net/htmlentities'>htmlentities</a>",
"<a href='http://www.php.net/exit'>exit</a>", "<a href='http://www.php.net/fputs'>fputs</a>",
"<a href='http://www.php.net/fgets'>fgets</a>", "<a href='http://www.php.net/mysql_pconnect'>mysql_pconnect</a>",
"<a href='http://www.php.net/mysql_select_db'>mysql_select_db</a>", "<a href='http://www.php.net/nl2br'>nl2br</a>",
"<a href='http://www.php.net/flush'>flush</a>", "<a href='http://www.php.net/explode'>explode</a>",
"<a href='http://www.php.net/str_replace'>str_replace</a>", "<a href='http://www.php.net/array'>array</a>",
"<a href='http://www.php.net/chr'>chr</a>", "<a href='http://www.php.net/rand'>rand</a>",
"<a href='http://www.php.net/mysql_query'>mysql_query</a>", "<a href='http://www.php.net/mysql_fetch_array'>mysql_fetch_array</a>",
"<a href='http://www.php.net/file_get_contents'>file_get_contents</a>", "<a href='http://www.php.net/preg_match'>preg_match</a>",
"<a href='http://www.php.net/substr_replace'>substr_replace</a>", "<a href='http://www.php.net/str_replace'>str_replace</a>",
"<a href='http://www.php.net/set_time_limit'>set_time_limit</a>", "<a href='http://www.php.net/isset'>isset</a>",
"<a href='http://www.php.net/fopen'>fopen</a>", "<a href='http://www.php.net/trim'>trim</a>",
"<a href='http://www.php.net/eregi'>eregi</a>", "<a href='http://www.php.net/die'>die</a>",
"<a href='http://www.php.net/microtime'>microtime</a>", "<a href='http://www.php.net/fwrite'>fwrite</a>",
"<a href='http://www.php.net/error_reporting'>error_reporting</a>", "<a href='http://www.php.net/strlen'>strlen</a>",
"<a href='http://www.php.net/preg_match'>preg_match</a>", "<a href='http://www.php.net/file'>file</a>",
"<a href='http://www.php.net/addslashes'>addslashes</a>", "<a href='http://www.php.net/get_magic_quotes_gpc'>get_magic_quotes_gpc</a>",
"<a href='http://www.php.net/md5'>md5</a>", "<a href='http://www.php.net/setcookie'>setcookie</a>",
"<a href='http://www.php.net/time'>time</a>", "<a href='http://www.php.net/getdate'>getdate</a>",
"<a href='http://www.php.net/sizeof'>sizeof</a>", "<a href='http://www.php.net/strpos'>strpos</a>",
"<a href='http://www.php.net/count'>count</a>", "<a href='http://www.php.net/phpinfo'>phpinfo</a>",
"<a href='http://www.php.net/ereg'>ereg</a>", "<a href='http://www.php.net/exec'>exec</a>",
"<a href='http://www.php.net/opendir'>opendir</a>", "<a href='http://www.php.net/is_dir'>is_dir</a>",
"<a href='http://www.php.net/mail'>mail</a>", "<a href='http://www.php.net/sha*'>sha*</a>");
$theoldphpcode = str_replace("<", "<", $thephpcode);
$theolderphpcode = str_replace(">", ">", $theoldphpcode);
$thenewphpcode = stripslashes(str_replace($thekeywords, $thelinkarrays, $theolderphpcode));
print "<pre>$thenewphpcode</pre>";
} else {
echo <<< HTMLTWO
<center><font color="0066FF" face="Verdana"><h*>PHP Keyword Parser v0.*</h*></font></center>
<center><font face ="Verdana">Enter your PHP code into the text box below, and then press 'Parse'</font></center>
<br>
<form name="thephpcodeform" action="$PHP_SELF" method="POST">
<center><textarea name="thephpcode" rows="22" cols="*00%"></textarea><center>
<input type="submit" value="Parse">
</form>
</body>
</html>
HTMLTWO;
};
?>
Plans for version 0.2
Fix the parsing problems when keywords are within keywords
Better formatting, basic syntax highlighting
Finding a more efficient way to do this other than manually entering all the values in an array. I was thinking of a foreach() but I'm thinking about how it'll work
<?php
/* PHP Keyword Parser v0.* */
/* Coded By Moonbat (with help from coz) */
echo <<< HTMLONE
<html>
<head>
<title>PHP Keyword Parser v0.*</title>
<style type="text/css">
textarea
{
background: black;
color: #FFFFFF;
}
a:link
{
color: #FFFFFF;
font-weight: bold;
}
a:visited
{
color: #FFFFFF;
font-weight: bold;
}
pre
{
color: white;
background: #444;
display: block;
margin: 0 *0px *2px;
overflow: auto;
padding: 8px *0px
}
</style>
</head>
<body bgcolor="666666">
HTMLONE;
if (isset($_POST['thephpcode'])){
$thephpcode = $_POST['thephpcode'];
$thekeywords = array("echo", "print", "fsockopen", "htmlentities",
"exit", "fputs", "fgets", "mysql_pconnect", "mysql_select_db", "nl2br", "flush", "explode",
"str_replace", "array", "chr", "rand", "mysql_query", "mysql_fetch_array", "file_get_contents",
"preg_match", "substr_replace", "str_replace", "set_time_limit", "isset", "fopen", "trim", "eregi",
"die", "microtime", "fwrite", "error_reporting", "strlen", "preg_replace", "file", "addslashes",
"get_magic_quotes_gpc", "md5", "setcookie", "time", "getdate", "sizeof", "strpos", "count",
"phpinfo", "ereg", "exec", "opendir", "is_dir", "mail", "sha*");
$thelinkarrays = array("<a href='http://www.php.net/echo'>echo</a>", "<a href='http://www.php.net/print'>print</a>",
"<a href='http://www.php.net/fsockopen'>fsockopen</a>", "<a href='http://www.php.net/htmlentities'>htmlentities</a>",
"<a href='http://www.php.net/exit'>exit</a>", "<a href='http://www.php.net/fputs'>fputs</a>",
"<a href='http://www.php.net/fgets'>fgets</a>", "<a href='http://www.php.net/mysql_pconnect'>mysql_pconnect</a>",
"<a href='http://www.php.net/mysql_select_db'>mysql_select_db</a>", "<a href='http://www.php.net/nl2br'>nl2br</a>",
"<a href='http://www.php.net/flush'>flush</a>", "<a href='http://www.php.net/explode'>explode</a>",
"<a href='http://www.php.net/str_replace'>str_replace</a>", "<a href='http://www.php.net/array'>array</a>",
"<a href='http://www.php.net/chr'>chr</a>", "<a href='http://www.php.net/rand'>rand</a>",
"<a href='http://www.php.net/mysql_query'>mysql_query</a>", "<a href='http://www.php.net/mysql_fetch_array'>mysql_fetch_array</a>",
"<a href='http://www.php.net/file_get_contents'>file_get_contents</a>", "<a href='http://www.php.net/preg_match'>preg_match</a>",
"<a href='http://www.php.net/substr_replace'>substr_replace</a>", "<a href='http://www.php.net/str_replace'>str_replace</a>",
"<a href='http://www.php.net/set_time_limit'>set_time_limit</a>", "<a href='http://www.php.net/isset'>isset</a>",
"<a href='http://www.php.net/fopen'>fopen</a>", "<a href='http://www.php.net/trim'>trim</a>",
"<a href='http://www.php.net/eregi'>eregi</a>", "<a href='http://www.php.net/die'>die</a>",
"<a href='http://www.php.net/microtime'>microtime</a>", "<a href='http://www.php.net/fwrite'>fwrite</a>",
"<a href='http://www.php.net/error_reporting'>error_reporting</a>", "<a href='http://www.php.net/strlen'>strlen</a>",
"<a href='http://www.php.net/preg_match'>preg_match</a>", "<a href='http://www.php.net/file'>file</a>",
"<a href='http://www.php.net/addslashes'>addslashes</a>", "<a href='http://www.php.net/get_magic_quotes_gpc'>get_magic_quotes_gpc</a>",
"<a href='http://www.php.net/md5'>md5</a>", "<a href='http://www.php.net/setcookie'>setcookie</a>",
"<a href='http://www.php.net/time'>time</a>", "<a href='http://www.php.net/getdate'>getdate</a>",
"<a href='http://www.php.net/sizeof'>sizeof</a>", "<a href='http://www.php.net/strpos'>strpos</a>",
"<a href='http://www.php.net/count'>count</a>", "<a href='http://www.php.net/phpinfo'>phpinfo</a>",
"<a href='http://www.php.net/ereg'>ereg</a>", "<a href='http://www.php.net/exec'>exec</a>",
"<a href='http://www.php.net/opendir'>opendir</a>", "<a href='http://www.php.net/is_dir'>is_dir</a>",
"<a href='http://www.php.net/mail'>mail</a>", "<a href='http://www.php.net/sha*'>sha*</a>");
$theoldphpcode = str_replace("<", "<", $thephpcode);
$theolderphpcode = str_replace(">", ">", $theoldphpcode);
$thenewphpcode = stripslashes(str_replace($thekeywords, $thelinkarrays, $theolderphpcode));
print "<pre>$thenewphpcode</pre>";
} else {
echo <<< HTMLTWO
<center><font color="0066FF" face="Verdana"><h*>PHP Keyword Parser v0.*</h*></font></center>
<center><font face ="Verdana">Enter your PHP code into the text box below, and then press 'Parse'</font></center>
<br>
<form name="thephpcodeform" action="$PHP_SELF" method="POST">
<center><textarea name="thephpcode" rows="22" cols="*00%"></textarea><center>
<input type="submit" value="Parse">
</form>
</body>
</html>
HTMLTWO;
};
?>
Plans for version 0.2
Fix the parsing problems when keywords are within keywords
Better formatting, basic syntax highlighting
Finding a more efficient way to do this other than manually entering all the values in an array. I was thinking of a foreach() but I'm thinking about how it'll work