If I want to try out something new in Ruby or Javascript, I love getting immediate feedback from irb or the JS console in Firebug.
Is there anything like that for PHP?
Update
As #bernie pointed out, such tools are called REPLs - "Read-eval-print loop"
Run php -a in the command-line. But this does not work on Windows.
For Windows, you may want to try phpa-norl.
Yes, there is a way: php -a,
-a means interactive shell
php -a is the closest thing I know of but it's not quite like irb. irb will execute each line at a time. php -a will wait until you press ctrl-D (for end of line) and will then execute all lines.
How about phpsh? It's not fully compatible with PHP, but it represents a serious effort.
http://www.phpsh.org
Boris
I'm not working with PHP currently, but I just spotted this online and remembered I had once asked this question. Boris looks very nice.
https://github.com/d11wtq/boris
If you have a Mac, I find the PHP Code Tester program a much better way to accomplish the same thing: http://www.macupdate.com/app/mac/37328/php-code-tester
Related
There is a console program for morphological analysis of text https://tech.yandex.ru/mystem/.
Work with the program from the console is simple:
./mystem -lwd in.txt out.txt
I need to carry out a morphological analysis of the text by means of PHP, use the exec () function is impossible.
The easiest way, using PHP to write text to a file, then using a bash script and cron to analyze and save into another file.
But I would like a more convenient option as a PHP function mystem (string, param).
Compile and install extensions I can, but do not know how to write them.
I think the problem is very simple, because maybe someone is faced with the decision of this problem is the "fish"?
Total my question is, Does anyone have a ready solution where you can change only the name of the console program and the expansion will be ready? Thank U!
When I searched for a way to execute a PHP script within another PHP script, I found the function passthru() at http://www.php.net/manual/de/function.passthru.php. I scrolled down and saw something with the registry, command line and EXE files. Is it possible to run a EXE file from a PHP script (with passthru(), exec() or something else) on a server.
If it is possible, is there a way to get the result or output of the EXE file?
And if all works, is there a way to use .NET applications?
Thank you in advance :)
I'm sorry, if my English isn't very good.
According to the manual passthru() does whats on the label, it passes trough stdout. If there is a browser on the other side it gets directly send to that.
If you want the results you could try backticks, this works because PHP is loosely based on Perl. :)
So, for example:
$foo = `mybinaryprogramm someparameters $somemoreparametersrightfromavariable`;
#now go and do something usefull with $foo
I should mention that you should sanitize $somemoreparametersrightfromavariable somehow, but i hope that you see that as good practice. :)
One of the nice features of languages like Python, Ruby or LISP is the availability of an interactive shell. This goes in a Read-Eval-Print Loop and allows to quickly experiment with the language without having to write and execute scripts.
Unfortunately PHP has nothing like that out of the box, but one can find some external tools online. I found three and I'm not sure which are the relative advantages?
Did anyone try one of those shells and can give some advice about which one to use?
Unfortunately PHP has nothing like that out of the box
Yes, it does. php -a or php --interactive are what you're looking for. They're useless before PHP 5.3 (segfaulty promptless <?php-prefix-requiring crap), but they fixed it up pretty well... just don't do anything that will trigger a fatal error.
Oh, and if you need to include a file that tries to do use getopt, you can make it work by opening the prompt thusly:
php -a -- --custom -s -t -u --ff="goes here" --the=first --double-dash --is="Magic!"
php -a
via command line invokes the interactive shell
I've found Facebook's (Python based!) PHP shell to work great, I've never gotten PHP built in interactive shell to work without custom compiling.
I want to be able to use the arrow keys when i pipe output from a php cli script into less. At the moment php cli does something to the tty which can only be fixed when you execute
!stty sane
from within less, which is a right pain!
I found a reference to this problem # http://www.php.net/manual/en/features.commandline.php#90743 but i can't seem to find an answer :-)
Any help is appreciated, although this problem ranks far below many other problems ;-)
I've been searching for some tweakable to do exactly this. Right now my best workaround is:
php blah.php </dev/null | less
which has the desired effect, but is a pita to have to type. It seems that when the PHP CLI detects stdin is a tty, it puts that tty into linemode.
If you add exec('stty cbreak'); to your cli script, it fixes this. (At least, it does for me, modifying drush.php for this.)
Another options that's slightly more readable (to me) is:
less -f <(php whatevz.php)
This is also useful when trying to pipe the output of PHP's info flag:
less -f <(php -i)
Having a python interpreter is really useful as it lets you quickly type in few commands and verify output; making it easier to understand syntax.
However, in PHP, every time I want to try something out I have to - create a PHP script, save it, run it in my browser.
Is there a shortcut that I am missing out on for PHP that would make things simpler?
You can run php CLI in interactive mode ;)
php -a
in interactive mode you need to type the script with start and end tags
<?php echo 'Hello!'; ?>
Use PHP Designer. It will make your job much easier.
Or you could use phpUnit , unit testing for php