【发布时间】:2016-07-20 22:16:33
【问题描述】:
我正在使用 php5 并且有一个脚本可以返回客户端的 IP 地址。 使用 shell_exec() 函数执行脚本。现在输出是这样的:*192.168.10.40 192.168.10.41 *。 现在我需要将它存储在一个数组中。我使用了 preg_match() 但它不起作用。
这是使用 preg_match() 的代码:
$test = shell_exec("/www/dhcp.sh");
$pattern='/([^ ]*) /';
preg_match($pattern, $test, $new);
preg_match() 返回 0;
这是我使用的explode():
$test = shell_exec("/www/dhcp.sh");
var_dump( explode(' ', $test ) );
我也使用了爆炸,但我得到的结果是: array(1) { [0]=> string(28) "192.168.10.40 192.168.10.41" } 谁能告诉我如何将字符串拆分为数组?
问候,
苏米亚
【问题讨论】:
-
你应该显示你正在使用的代码。