phpreadline
❶ php常用扩展有哪些
php基本使用到的扩展有如下:
bcmath(精确数值处理)
bz2
calendar
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
gettext
hash
iconv
igbinaryinotify 文件监控
json
libxml
mbstring
mhash
mysql
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
redis Redis缓存
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshmswoole 通信引擎
tokenizer
wddx
xml
xmlreader
xmlwriter
xslyaf YAF框架必须
zip
zlib
其中最常用的扩展有:curl date json mysql mysqli openssl pdo_mysql redis session zip等
查看当前php安装了哪些扩展,可以使用命令:php -m
❷ 如何使用PHP的交互式运行环境
从PHP 5.1.0开始,CLI SAPI提供了一个交互式命令行工具(Interactive shell),这个交互式PHP shell是通过使用 –with-readline 编译选项集成到php内核里的。使用这个交互式shell,你可以直接在命令行窗口里输入PHP并直接获得输出结果。
开启PHP的交互式shell模式,需要使用 -a 参数。下面是使用交互式shell的一些例子。
$ php -a
Interactive shell
php > echo 5+8;
13
php > function addTwo($n)
php > {
php { return $n + 2;
php { }
php > var_mp(addtwo(2));
int(4)
php >
在交互式shell里,你可以使用 tab 键对函数名,内置变量,类名,静态方法等进行自动补全操作。
需要注意的是,Interactive Shell 和 Interactive Mode 并不是一个东西,尽管名称和功能都很相似。
如果你输入 php -a ,得到的回应是 ‘Interactive Shell’ 并跟随着 ‘php>’ 提示符,那你使用的就是交互式shell。如果你得到的回应是 ‘Interactive mode enabled’ ,说明你的PHP并不支持交互式shell,上面介绍的用法也不实用于你。
但也不用担心,Interactive mode(交互模式)也可以在命令行窗口里执行PHP代码,只是代码的执行方式有些区别。在PHP交互模式(Interactive mode)里,你在命令行窗口里输入PHP代码,代码不会立即执行,当你输入了所有PHP代码后,输入 Ctrl-Z (windows里),或输入 Ctrl-D (linux里),你输入的所有代码将会一次执行完成并输出结果。
在PHP交互模式(Interactive mode)里,跟交互式shell里不一样,你的代码需要以 <?php 开头,跟你的普通PHP文件里的写法一致。下面是在Windows里的使用例子。
C:\>php -a
Interactive mode enabled
<?php
echo "Hello, world!";
?>
^Z
Hello, world!
在Winidows里,没有交互式shell,只有Interactive mode。
❸ php计算n要求n为键盘输入的数字
您好,您想要通过 PHP 计算用户输入的数字吗?这是可以做到的,下面清伍巧是一个简单的例子:
// 读取用户在键答键盘输入的数字
$n = readline("请输入一个数字:");
// 计算并输出结果
echo "您输入的数字是:" . $n . "\n";
在这个例子中,我们通过 readline 函数来读取用户在键盘橘碰输入的数字,然后通过 echo 输出结果。
希望这对您有帮助。
❹ PHP的扩展中回调PHP的函数有多参数的问题
写PHP扩展最好的参考资料是官方代码库,即便不算best practice,也不至于太差。先下载一份php源码,然后在ext目录里搜 call_user_function,把参数个数>=2的列出来。比如 ext/readline/readline.cstatic char **_readline_completion_cb(const char *text, int start, int end)
{
zval params[3];
int i;
char **matches = NULL;
_readline_string_zval(¶ms[0], text);
_readline_long_zval(¶ms[1], start);
_readline_long_zval(¶ms[2], end);
if (call_user_function(CG(function_table), NULL, &_readline_completion, &_readline_array, 3, params) == SUCCESS) {
if (Z_TYPE(_readline_array) == IS_ARRAY) {
if (zend_hash_num_elements(Z_ARRVAL(_readline_array))) {
matches = rl_completion_matches(text,_readline_command_generator);
} else {
matches = malloc(sizeof(char *) * 2);
if (!matches) {
return NULL;
}
matches[0] = strp("");
matches[1] = '\0';
}
}
}
for (i = 0; i < 3; i++) {
zval_ptr_dtor(¶ms[i]);
}
zval_ptr_dtor(&_readline_array);
return matches;
}
看一下call_user_function的签名,它参数是个数组,zval params[]ZEND_API int _call_user_function_ex(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], int no_separation);
#define call_user_function(function_table, object, function_name, retval_ptr, param_count, params) \
_call_user_function_ex(object, function_name, retval_ptr, param_count, params, 1)
#define call_user_function_ex(function_table, object, function_name, retval_ptr, param_count, params, no_separation, symbol_table) \
_call_user_function_ex(object, function_name, retval_ptr, param_count, params, no_separation)