monitoring
+ Reply to Thread
Results 1 to 9 of 9

Thread: PHP Project Help Needed

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

    PHP Project Help Needed

    Alright, well, I'm working on a project, here is the gist of what it is. I got the idea from another site.

    When someone is reading PHP code, they might wonder what a certain function, like 'explode' or 'nl2br' does. They would probably Google it up. But this makes the process easier. What you do is enter your PHP code into the text box, and then when you submit it, it'll output the PHP code, but with many important statements and functions already hyperlinked to the PHP.net function reference. It may not be particularly useful, but it's my first short-term project.

    Sadly, I've come accross my first hurdle. Here is the full code:
    [PHP]<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;
    }
    </style>
    </head>
    <body bgcolor="666666">

    <?php
    if (isset($_POST['thephpcode'])){
    $thephpcode = $_POST['thephpcode'];
    $thekeywords = array("echo", "print", "fsockopen");
    $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>");
    str_replace($thekeywords, $thelinkarrays, $thephpcode);
    print "<pre>$thephpcode</pre>";
    } ;
    ?>

    <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 echo $PHP_SELF; ?>" method="POST">
    <center><textarea name="thephpcode" rows="22" cols="*00%"></textarea><center>
    <input type="submit" value="Parse">
    </form>
    </body>
    </html>[/PHP]
    I get no errors (and I haven't done anything to suppress errors, such as @, so I should get errors if there are any because I've gotten them before).

    But the problem is when I enter in the code, it just echoes back the code instead of replacing the specified keywords with the linked versions. I've checked the code >*000 times and I can't figure out why it isn't working. I'm testing this on AwardSpace webhost, but I don't think that makes any difference.

    If you can help, I'd appreciate it.
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  2. #2
    Join Date
    Dec 2007
    Posts
    141
    I'm don't know much about php and should even be saying anything but it looks like you never told it to do anything to the entered text. You just put a bunch of keywords and things in variables/arrays but none of them ever get worked on (ran through a loop or string comparison or something).

  3. #3
    Join Date
    Sep 2006
    Posts
    1,649
    Actually, it does do something :P I'll explain it:
    [PHP]if (isset($_POST['thephpcode'])){[/PHP]
    This line checks to see if there is any POST data from the form 'thephpcodeform' with the name 'thephpcode'.
    [PHP]$thephpcode = $_POST['thephpcode'];
    $thekeywords = array("echo", "print", "fsockopen");
    $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>"); [/PHP]
    This does three things.
    1. Assigns the POST data from the 'thephpcodeform' form to a stable variable
    2. Assigns the array of keywords echo, print, and fsockopen to a variable
    3. Assigns an array of the hyperlinked versions of the keywords to a variable
    [PHP]str_replace($thekeywords, $thelinkarrays, $thephpcode);
    print "<pre>$thephpcode</pre>";
    } ; [/PHP]
    This (is supposed to) search for the keywords the variable $thekeywords holds in the string of PHP code named $thephpcode. It will replace those keywords with the ones in the variable $thelinkarrays. But that's not happening
    Last edited by Moonbat; 03-27-2008 at 06:59 PM.
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  4. #4
    Join Date
    Dec 2007
    Posts
    141
    It looks to me like the str_replace function is the only thing that may attempt to do something but it doesn't return a value to do it. Maybe it doesn't have to to use the function? Just trying to help man.

  5. #5
    Join Date
    Sep 2006
    Posts
    1,649
    Quote Originally Posted by coz View Post
    It looks to me like the str_replace function is the only thing that may attempt to do something but it doesn't return a value to do it. Maybe it doesn't have to to use the function? Just trying to help man.
    I feel really stupid now

    I realized that I forgot to assign the result of the str_replace() function to a variable.

    But now that I've realized it (thanks to coz), my script finally works! All I gotta do is fill in the rest of the keywords

    Muchas gracias coz, don't know what I'd do without you

    [url=http://www.encyclopediadramatica.com/images/4/47/You_win_the_prize.jpg]Oh, BTW coz, here is your prize...[/url]
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  6. #6
    Join Date
    Aug 2007
    Posts
    122

    Keyword To Link Function ?

    Not sure I fully understand the idea. Do you mean something like the following?

    It's built around a simple function to convert a PHP function keyword into an HTML hyperlink string to the corresponding PHP manual page.

    It wouldn't be too difficult to create a button to go directly to the PHP manual when clicked.

    To demonstrate the function, the generated link is displayed on the page.

    Code:
    <?PHP
    
       $keyword = @$_POST['keyword'];
    
       $link = Keyword_To_Link ($keyword);
    
    
    print <<< _HTML
    <!DOCTYPE HTML PUBLIC "-//W*C//DTD HTML 4.0* Transitional//EN"
    "http://www.w*.org/TR/html4/loose.dtd">
    
    <HTML>
    <HEAD>
    
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-885*-*">
    
    <TITLE>Lookup PHP Keyword</TITLE>
    
    </HEAD>
    
    <BODY>
    
    <FORM NAME="KeywordForm" METHOD="post" ACTION="kw.php">
    
    <TABLE WIDTH="264" BORDER="*">
    
    <TR><TD COLSPAN="2" ALIGN="CENTER"><B>Enter PHP Function Keyword</B></TD></TR>
    
    <TR>
    <TD WIDTH="**2"><INPUT NAME="keyword" TYPE="text" SIZE="*2" MAXLENGTH="*2" VALUE="$keyword"></TD>
    <TD WIDTH="56"><INPUT  TYPE="submit" NAME="Submit" VALUE="Make Link"></TD>
    </TR>
    
    </TABLE>
    
    <P>$link</P>
    
    </FORM>
    
    </BODY>
    </HTML>
    
    _HTML;
    
    
       function Keyword_To_Link ($KeywordArg)
    
    {
       $BaseURL = "http://us2.php.net/manual/en/";
       $keyword = StrToLower(trim($KeywordArg));
         $HLink = "<A HREF=\"$BaseURL" . "function.$keyword.php\">$keyword</A>";
    
       return $HLink;
    }
    
    
    ?>
    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!

  7. #7
    Join Date
    Sep 2006
    Posts
    1,649
    Not exactly JayT. Your code will only take one keyword and produce a link to it. What I aim to do is let the user enter a bunch of PHP code (wthout the beginning and ending tags). Once entered, my script will go through and look for a large list of keywords, and if it finds any, it'll replace them with a link to the database. For example, my script will turn:
    echo "hai";
    fsockopen(insertrandomcarajflkfjkasljfopwopa);
    print "y halo thar?";
    $var ajflka = array("faksjflk", "kfajslfk", "kdfjasld");
    Into:
    [url=http://php.net/echo]echo[/url] "hai";
    [url=http://php.net/fsockopen]fsockopen[/url](insertrandomcarajflkfjkasljfopwopa);
    [url=http://php.net/print]print[/url] "y halo thar?";
    $var ajflka = [url=http://php.net/array]array[/url]("faksjflk", "kfajslfk", "kdfjasld");
    Right now I've got it working, just working on the formatting and look of the whole thing.
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  8. #8
    Join Date
    Dec 2007
    Posts
    141
    What can I say, It's great to be the man. That's one funny ass prize man.

  9. #9
    Join Date
    Aug 2007
    Posts
    122

    Da Oui Ja Si

    Quote Originally Posted by Moonbat View Post
    Not exactly JayT. Your code will only take one keyword and produce a link to it.

    Yes, I know. That was the idea. It was to demonstrate the core concept.

    I thought a simple function to convert a keyword to a link might be called from within a loop to handle that single task in a independent modular fashion. Then you could cycle through the array calling the function for each keyword.

    I built a huge library of custom functions and use them to create programs without reinventing the wheel each time.

    The keyword to link function was one of many.

    My usual style is to create modular, compatible building block functions that I can assemble and combine as needed like leggos to build projects.

    It's like extending the PHP language and adding your own new custom functions.


    Saves me work.

    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!

+ Reply to Thread

Similar Threads

  1. Programming Project Help
    By blacksabbath in forum Programming
    Replies: 0
    Last Post: 10-24-2008, 05:49 PM
  2. [PHP] Solving Euler Project #2
    By Moonbat in forum Programming
    Replies: 1
    Last Post: 07-24-2008, 04:36 PM
  3. [PHP] Solving Euler Project #*
    By Moonbat in forum Programming
    Replies: 1
    Last Post: 07-13-2008, 04:38 PM
  4. Help needed.
    By Water-Dragon in forum Internet Privacy
    Replies: 23
    Last Post: 12-11-2006, 12:24 AM

Posting Permissions

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