munin
+ Reply to Thread
Results 1 to 6 of 6

Thread: PHP Keyword Parser v0.*

  1. #1
    Join Date
    Sep 2006
    Posts
    1,649

    PHP Keyword Parser v0.*

    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
    /* 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("<", "&lt;", $thephpcode);
    $theolderphpcode = str_replace(">", "&gt;", $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;
    };
    ?>[/PHP]
    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
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  2. #2
    Join Date
    Aug 2007
    Posts
    122

    Interesting Concept

    Perhaps you should work with the keywords contained in a text file.

    Then read the keywords & convert them into links from the file.

    It would decrease the size and complexity of the code.




    Here are a couple more PHP keywords you could add:

    [url]http://neoprogrammics.com/php5.txt[/url]


    Cheers

    Oh to be free, so blissfully free, of the ravages of intelligence, there is no greater joy! - The Cweationist's Cweed

    All that is necessary for evil to triumph is a good PR firm.
    Very funny, Scotty. Now beam down my clothes!

  3. #3
    Join Date
    Sep 2006
    Posts
    1,649
    Hmm... reading from a text file wouldn't be a bad idea. But I'm not sure how I'd implement it. I'd have to get all of the keywords in a text file, put them in an array, and probably use a foreach() to make links. I'll have to look into that more.

    Also, thanks for the keywords, I'll definately be adding more once I fix the keyword-in-a-keyword issue.
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  4. #4
    Join Date
    Jan 2005
    Posts
    623
    MoooooN

    I thought something like this might make it easier on you:
    [php]
    <?PHP
    // CURRENT WORD YOU ARE CHECKING
    $CURRENT_WORD_TO_CHECK='echo';
    // DEFAULT IMAGE TO USE FOR QUESTION MARK ICON
    $QUESTION_MARK_IMAGE='root/images/questionmark.jpg';



    /* YOU SHOULD PUT THE FOLLOWING FUNCTION IN A SEPERATE FILE AND
    INCLUDE THE FILE AT THIS TIME. */
    $this_is_a_function['echo']=array(
    'description' => 'Here is the description of the echo function',
    'url' => array(
    'http://www.url_for_echo_function',
    'http://www.2nd_url_for_echo_funciton'),
    'color' => '#******'
    );
    // END OF INCLUDE FILE


    // CHECKS TO SEE IF FUNCTION EXIST FOR CURRENT WORD
    if($this_is_a_function[$CURRENT_WORD_TO_CHECK]){
    /* IF FUNCTION EXIST IT WILL COLOR THE KEYWORD AND LINK IT BY
    RANDOMLY SELECTING A URL TO HYPERLINK THE TEXT WITH. NEXT IT WILL
    PLACE THE QUESTION MARK IMAGE NEXT TO THE WORD. WHEN YOU MOUSE
    OVER THE QUESTION MARK YOU WILL GET THE FUNCTION DESCRIPTION. */
    ?>
    <a style="color:<?=$this_is_a_function[$CURRENT_WORD_TO_CHECK]['color']?>" href="<?=$this_is_a_function[$CURRENT_WORD_TO_CHECK]['url'][rand(0,count($this_is_a_function[$CURRENT_WORD_TO_CHECK]['url'])-*)]?>"><?=$CURRENT_WORD_TO_CHECK?></a>
    <img src="<?=$QUESTION_MARK_IMAGE?>" alt="<?=$this_is_a_function[$CURRENT_WORD_TO_CHECK]['description']?>" title="<?=$this_is_a_function[$CURRENT_WORD_TO_CHECK]['description']?>" width="*0px" height="*0px">
    <?
    }
    ?>
    [/php]
    [url=http://www.syntax******.info/tools/services.php]Speed Up Windows XP[/url]
    [url=http://www.syntax******.info/tools/ip.php]Get An Ip Address[/url]
    [url=http://www.syntax******.info/tools/base_converter.php]Base Converter[/url]
    --------------------------------
    [URL=http://www.boninroad.com/syntax******/]Old Site[/URL]
    [URL=http://www.syntax******.info]Comming Soon[/URL]

  5. #5
    Join Date
    Sep 2006
    Posts
    1,649
    This is a nifty little function. I'll try to implement it, thanks dude
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  6. #6
    Join Date
    Sep 2006
    Posts
    1,649
    Well, I kind of abandoned this project, most due to the syntax highlighting issue (I hate regular expressions). But I found this nice PHP function:

    [URL="http://us*.php.net/manual/en/function.highlight-string.php"]highlight_string()[/URL]

    To think I could have saved a lot of time and effort if I had known about this function before. But yeah, I might redo this project a little bit and make it into a standalone function
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts