0

我使用以下方法找到了解决方案 mysqlf:

foreach ($output as $value) {
    if (strpos($value, "]:") > -1) {
        $tal = substr($value, strpos($value, "]:") +3) . "<br>";
        echo $tal;
    }
}

这返回:-210 -212


提前致谢。

我想怀孕所以我只得到这条线: [10] => [147]: -210 或两者 [10] => [147]: -210 和 [21] => [148]: -212

我怎样才能怀孕[147]:或有更好的方法来获取具体信息?

我的数组 $output 包含:

Array
(
    [0] => modpoll 3.4 - FieldTalk(tm) Modbus(R) Master Simulator
    [1] => Copyright (c) 2002-2013 proconX Pty Ltd
    [2] => Visit http://www.modbusdriver.com for Modbus libraries and tools.
    [3] => 
    [4] => Protocol configuration: MODBUS/TCP
    [5] => Slave configuration...: address = 1, start reference = 147, count = 1
    [6] => Communication.........: 10.234.6.11, port 502, t/o 1.00 s, poll rate 1000 ms
    [7] => Data type.............: 16-bit register, output (holding) register table
    [8] => 
    [9] => -- Polling slave...
    [10] => [147]: -210
    [11] => modpoll 3.4 - FieldTalk(tm) Modbus(R) Master Simulator
    [12] => Copyright (c) 2002-2013 proconX Pty Ltd
    [13] => Visit http://www.modbusdriver.com for Modbus libraries and tools.
    [14] => 
    [15] => Protocol configuration: MODBUS/TCP
    [16] => Slave configuration...: address = 1, start reference = 148, count = 1
    [17] => Communication.........: 10.234.6.11, port 502, t/o 1.00 s, poll rate 1000 ms
    [18] => Data type.............: 16-bit register, output (holding) register table
    [19] => 
    [20] => -- Polling slave...
    [21] => [148]: -212
)

$matches  = preg_grep ('/^[147] (\w+)/i', $output);
print_r ($matches);
//only returns Array()
4

1 回答 1

0

您需要转义左方括号,因为[147]它被视为包含1,47

你可以这样做:

$result=preg_grep('~^\[14(?:7|8)]:~',$rgData);
print_r($result);

您可以在此处找到有关转义(或不转义)方括号的所有信息

于 2013-08-08T13:22:25.280 回答