I'm using Ubuntu 12.04 64 bit and I want to use the PHP interactive shell:
我正在使用Ubuntu 12.04 64位,我想使用PHP交互式shell:
php -a
But it doesn't seem to work very well, a lot of syntax is incorrectly interpreted.
但它似乎不能很好地工作,很多语法被错误地解释。
When I run php -a
it displays:
当我运行php -a时,它会显示:
interactive mode enabled
And just a cursor blinking.
只是一个光标闪烁。
I'm using: PHP 5.4.13-2~precise+1 (cli) (built: Mar 21 2013 12:17:18)
我正在使用:PHP 5.4.13-2~precision + 1(cli)(内置:2013年3月21日12:17:18)
How do I use the PHP interactive shell?
我如何使用PHP交互式shell?
4 个解决方案
#1
8
Try installing http://www.phpsh.org/ it is probably the easiest solution.
尝试安装http://www.phpsh.org/这可能是最简单的解决方案。
Steps: (assuming dependency's installed)
步骤:(假设已安装依赖项)
git clone https://github.com/facebook/phpsh
cd phpsh
sudo python setup.py install
phpsh
git clone https://github.com/facebook/phpsh
sudo python setup.py安装
#2
7
This is what you'll get when the php5-readline
package is not installed. Assuming that's your problem you can fix it by running this command:
这是你没有安装php5-readline包时会得到的。假设这是您的问题,您可以通过运行此命令来修复它:
sudo apt-get install php5-readline
#3
6
How to use the PHP interactive shell
phpsh was made by facebook. To install it see this: http://www.phpsh.org/
phpsh是由facebook制作的。要安装它,请访问:http://www.phpsh.org/
Installation directions:
sudo apt-get install git
cd /home/youruser;
Pull the repository, cd into it and install:
拉出存储库,cd进入它并安装:
git clone https://github.com/facebook/phpsh
cd phpsh
sudo python setup.py install
Run it:
el@apollo:~$ phpsh
Starting php
type 'h' or 'help' to see instructions & features
php>
Walkthrough:
Printing strings:
php> echo 'hi';
hi
Do some math:
做一些数学:
php> echo 1+2;
3
Print some builtin variables:
打印一些内置变量:
php> echo $_SERVER;
Array
Print contents of that array:
打印该数组的内容:
php> print_r($_SERVER);
Array
(
[LANG] => en_US.UTF-8
[TERM] => xterm
[SHELL] => /bin/bash
)
Get a key of that array:
获取该数组的一个键:
php> echo $_SERVER['TERM'];
xterm
Addition of a different kind:
添加不同类型:
php> =2+2
4
Print the previous:
打印上一个:
php> = $_
4
Store a variable:
存储变量:
php> $msg = "don't just sit there fancy pants, take the wheel";
php> echo $msg;
don't just sit there fancy pants take the wheel
An equation can be held open through newlines until it completes:
方程式可以通过换行符保持打开直到完成:
php> =2+
... 3+
... 4+5
14
Define our own arrays:
定义我们自己的数组:
php> $derp = array(1,2,3);
php> echo $derp
Array
Get the type of a variable:
获取变量的类型:
php> echo gettype(PHP_VERSION);
string
For great justice, loops:
为了伟大的正义,循环:
php> $i = 0; while ($i < 3){$i++; echo "pinkie pie is best pony ";}
pinkie pie is best pony pinkie pie is best pony pinkie pie is best pony
Get yerself some info:
获取自己的一些信息:
php> phpinfo();
phpinfo();
PHP Version => 5.3.10-1ubuntu3.8
Explode parses the string on space into an array, print_r pretty prints it:
Explode将空间上的字符串解析为数组,print_r将其打印出来:
php> function little_bad_girl(){ print_r(explode(" ", "oxy contin")); }
php> little_bad_girl();
Array
(
[0] => oxy
[1] => contin
)
Foreach structure can be extended onto following lines.
Foreach结构可以扩展到以下行。
php> foreach (array(1,2,3) as $item) {
... echo $item;
... }
123
Block comments are ignored:
阻止评论被忽略:
php> /* echo "hidden"; */
php>
Read from a file:
从文件中读取:
php> $section = file_get_contents('/home/el/myfile.txt');
php> echo $section;
we will become a spacefaring civilization.
No, no time:
不,没时间:
php> echo time();
1386492405
Pure sweet truth:
纯正的甜蜜真相:
php> echo isset($_SERVER);
1
Make an array, search for an item in it.
创建一个数组,搜索其中的项目。
php> $data = array(0, 1, 2);
php> echo preg_grep("/1/", $data);
Array
php> print_r( preg_grep("/1/", $data));
Array
(
[1] => 1
)
php> print_r( preg_grep("/4/", $data));
Array
(
)
You want more??? There is enough to fill a lifetime, godspeed: http://php.about.com/od/advancedphp/
你想要更多???有足够的时间填补一生,速度:http://php.about.com/od/advancedphp/
#4
2
How about PsySH ?
PsySH怎么样?
A litle example :
一个小例子:
psysh
Psy Shell v0.7.2 (PHP 5.5.12-2ubuntu4.6 — cli) by Justin Hileman
>>> $toto='ejgf5d78gfmkzl'
=> "ejgf5d78gfmkzl"
>>> substr($toto,0,2)
=> "ej"
#1
8
Try installing http://www.phpsh.org/ it is probably the easiest solution.
尝试安装http://www.phpsh.org/这可能是最简单的解决方案。
Steps: (assuming dependency's installed)
步骤:(假设已安装依赖项)
git clone https://github.com/facebook/phpsh
cd phpsh
sudo python setup.py install
phpsh
git clone https://github.com/facebook/phpsh
sudo python setup.py安装
#2
7
This is what you'll get when the php5-readline
package is not installed. Assuming that's your problem you can fix it by running this command:
这是你没有安装php5-readline包时会得到的。假设这是您的问题,您可以通过运行此命令来修复它:
sudo apt-get install php5-readline
#3
6
How to use the PHP interactive shell
phpsh was made by facebook. To install it see this: http://www.phpsh.org/
phpsh是由facebook制作的。要安装它,请访问:http://www.phpsh.org/
Installation directions:
sudo apt-get install git
cd /home/youruser;
Pull the repository, cd into it and install:
拉出存储库,cd进入它并安装:
git clone https://github.com/facebook/phpsh
cd phpsh
sudo python setup.py install
Run it:
el@apollo:~$ phpsh
Starting php
type 'h' or 'help' to see instructions & features
php>
Walkthrough:
Printing strings:
php> echo 'hi';
hi
Do some math:
做一些数学:
php> echo 1+2;
3
Print some builtin variables:
打印一些内置变量:
php> echo $_SERVER;
Array
Print contents of that array:
打印该数组的内容:
php> print_r($_SERVER);
Array
(
[LANG] => en_US.UTF-8
[TERM] => xterm
[SHELL] => /bin/bash
)
Get a key of that array:
获取该数组的一个键:
php> echo $_SERVER['TERM'];
xterm
Addition of a different kind:
添加不同类型:
php> =2+2
4
Print the previous:
打印上一个:
php> = $_
4
Store a variable:
存储变量:
php> $msg = "don't just sit there fancy pants, take the wheel";
php> echo $msg;
don't just sit there fancy pants take the wheel
An equation can be held open through newlines until it completes:
方程式可以通过换行符保持打开直到完成:
php> =2+
... 3+
... 4+5
14
Define our own arrays:
定义我们自己的数组:
php> $derp = array(1,2,3);
php> echo $derp
Array
Get the type of a variable:
获取变量的类型:
php> echo gettype(PHP_VERSION);
string
For great justice, loops:
为了伟大的正义,循环:
php> $i = 0; while ($i < 3){$i++; echo "pinkie pie is best pony ";}
pinkie pie is best pony pinkie pie is best pony pinkie pie is best pony
Get yerself some info:
获取自己的一些信息:
php> phpinfo();
phpinfo();
PHP Version => 5.3.10-1ubuntu3.8
Explode parses the string on space into an array, print_r pretty prints it:
Explode将空间上的字符串解析为数组,print_r将其打印出来:
php> function little_bad_girl(){ print_r(explode(" ", "oxy contin")); }
php> little_bad_girl();
Array
(
[0] => oxy
[1] => contin
)
Foreach structure can be extended onto following lines.
Foreach结构可以扩展到以下行。
php> foreach (array(1,2,3) as $item) {
... echo $item;
... }
123
Block comments are ignored:
阻止评论被忽略:
php> /* echo "hidden"; */
php>
Read from a file:
从文件中读取:
php> $section = file_get_contents('/home/el/myfile.txt');
php> echo $section;
we will become a spacefaring civilization.
No, no time:
不,没时间:
php> echo time();
1386492405
Pure sweet truth:
纯正的甜蜜真相:
php> echo isset($_SERVER);
1
Make an array, search for an item in it.
创建一个数组,搜索其中的项目。
php> $data = array(0, 1, 2);
php> echo preg_grep("/1/", $data);
Array
php> print_r( preg_grep("/1/", $data));
Array
(
[1] => 1
)
php> print_r( preg_grep("/4/", $data));
Array
(
)
You want more??? There is enough to fill a lifetime, godspeed: http://php.about.com/od/advancedphp/
你想要更多???有足够的时间填补一生,速度:http://php.about.com/od/advancedphp/
#4
2
How about PsySH ?
PsySH怎么样?
A litle example :
一个小例子:
psysh
Psy Shell v0.7.2 (PHP 5.5.12-2ubuntu4.6 — cli) by Justin Hileman
>>> $toto='ejgf5d78gfmkzl'
=> "ejgf5d78gfmkzl"
>>> substr($toto,0,2)
=> "ej"