Interactive PHP like Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • j_macaroni@yahoo.com

    Interactive PHP like Python

    I know you can start php -a and go into interactive mode. This works
    well exept you have to keep putting <?php code here ; bla blah code ;

    Couple of problems with this.

    1) Exits php when you make an error.

    2) When you type a command; it displays the result but does not do an
    automatic CR/LF

    Would be nice if it opened up in a window, and you just type and press
    enter and see the result on the next line.

    Allow you to move up to a previous command and edit and press Enter.

    This would allow people to test commands and learn. You could even load
    personal functions from a php file to do some testing

    Anyone know of a nice php interactive shell like Python's?

    Thanks

  • Henk Verhoeven

    #2
    Re: Interactive PHP like Python

    Hi J,

    Why not build this yourself? This will only take you 10-30 minutes, much
    less then searching for an interactive shell. All you need is a web
    server that runs php.

    Make a php script that outputs a form with a textarea where you can
    enter some php code. The form targets the same php script. The script
    outputs the form once again with the same php code that was entered.
    Then, below the form, it outputs a DIV with fixed sizes and a scroll bar
    (style=). After outputting the <DIV styl= > tag, pass the code from the
    textarea passed to php's eval function. This will run the code. Anything
    that is printed from the eval'd php code will appear inside the DIV.
    Then print the end of the DIV and the end of the page. Or before the end
    of the page add another scrollable DIV with in between <PRE> tags
    print_r the eval result.

    If you want a new line to start after printing, add a simple function
    printLn($aValue ) {
    print $aValue;
    print "<BR>\n";
    }
    and call it from the eval'd php code.

    WARNING: DO *NOT* put such a script on your website or any publically
    accessable web server directory as it would allow anyone to execute any
    php code on your server, allowing the reading of all its publically
    readable files, and probably hack you server.

    Greetings,

    Henk Verhoeven,
    www.phpPeanuts.org.



    j_macaroni@yaho o.com wrote:[color=blue]
    > I know you can start php -a and go into interactive mode. This works
    > well exept you have to keep putting <?php code here ; bla blah code ;
    >
    > Couple of problems with this.
    >
    > 1) Exits php when you make an error.
    >
    > 2) When you type a command; it displays the result but does not do an
    > automatic CR/LF
    >
    > Would be nice if it opened up in a window, and you just type and press
    > enter and see the result on the next line.
    >
    > Allow you to move up to a previous command and edit and press Enter.
    >
    > This would allow people to test commands and learn. You could even load
    > personal functions from a php file to do some testing
    >
    > Anyone know of a nice php interactive shell like Python's?
    >
    > Thanks
    >[/color]

    Comment

    • j_macaroni@yahoo.com

      #3
      Re: Interactive PHP like Python

      I was hoping not to reinvent the wheel. Maybe someone else knows of a
      module that does this. But I can see where it wouldnt be hard to
      develop.

      Henk Verhoeven wrote:[color=blue]
      > Hi J,
      >
      > Why not build this yourself? This will only take you 10-30 minutes, much
      > less then searching for an interactive shell. All you need is a web
      > server that runs php.
      >
      > Make a php script that outputs a form with a textarea where you can
      > enter some php code. The form targets the same php script. The script
      > outputs the form once again with the same php code that was entered.
      > Then, below the form, it outputs a DIV with fixed sizes and a scroll bar
      > (style=). After outputting the <DIV styl= > tag, pass the code from the
      > textarea passed to php's eval function. This will run the code. Anything
      > that is printed from the eval'd php code will appear inside the DIV.
      > Then print the end of the DIV and the end of the page. Or before the end
      > of the page add another scrollable DIV with in between <PRE> tags
      > print_r the eval result.
      >
      > If you want a new line to start after printing, add a simple function
      > printLn($aValue ) {
      > print $aValue;
      > print "<BR>\n";
      > }
      > and call it from the eval'd php code.
      >
      > WARNING: DO *NOT* put such a script on your website or any publically
      > accessable web server directory as it would allow anyone to execute any
      > php code on your server, allowing the reading of all its publically
      > readable files, and probably hack you server.
      >
      > Greetings,
      >
      > Henk Verhoeven,
      > www.phpPeanuts.org.
      >
      >
      >
      > j_macaroni@yaho o.com wrote:[color=green]
      > > I know you can start php -a and go into interactive mode. This works
      > > well exept you have to keep putting <?php code here ; bla blah code ;
      > >
      > > Couple of problems with this.
      > >
      > > 1) Exits php when you make an error.
      > >
      > > 2) When you type a command; it displays the result but does not do an
      > > automatic CR/LF
      > >
      > > Would be nice if it opened up in a window, and you just type and press
      > > enter and see the result on the next line.
      > >
      > > Allow you to move up to a previous command and edit and press Enter.
      > >
      > > This would allow people to test commands and learn. You could even load
      > > personal functions from a php file to do some testing
      > >
      > > Anyone know of a nice php interactive shell like Python's?
      > >
      > > Thanks
      > >[/color][/color]

      Comment

      • Electrum
        New Member
        • May 2006
        • 1

        #4
        Interactive PHP Shell

        I wrote such a script:

        Comment

        • David  Phillips

          #5
          Re: Interactive PHP like Python

          I wrote an interactive PHP shell, modeled after the Python shell:



          Comment

          Working...