How to translate this command to PHP-API?

This:
/ppp active print where address~“^172”

It returns all adresses starting with 172.
I couldnt find a way o do it in the PHP API, this is one of the commands i tried:
$API->write(‘/ppp/active/print’,false);
$API->write(‘=where=’,false);
$API->write(‘?address=~172.’);
$READ = $API->read(false);
$ARRAY = $API->parse_response($READ);
I also tried:
‘?address~“^172”’
‘?address~“172.”’
‘~address~“^172”’
everything with and without the " (double slashes)

No luck, it always returns 0 matches, but if i do:
‘?address=some.ip.adress’
It works.

Anyone know how to do it?

Well, I’m just a noob, but maybe this one work?

$API->write('/ppp/active/print',false);
// remove this one
// $API->write('=where=',false);
$API->write('~address~"172."');

Click here to find out the truth about regex in API

Doesnt work, it returns everything, doesnt filter :frowning:

Yeah… if you didn’t catch my drift with my previous post… What you are trying to do is not supported with the API protocol.

Yeah pretty sad, is there any modded API out there that supports it?

No, because this is a problem with the protocol itself, not the client.

You can always do the filtering on the client side, with this being easier with some clients than with others, but either way - all responses will have to travel between the router and the web server. With some clients (such as the one from my signature), there is also a way to process responses one by one, rather than together, but that only helps your web server’s memory, not your network bandwidth.

If keeping your web server’s memory consumption low is exactly what you’re worried about, using my client, you can keep it low like this:

$printRequest = new Request('/ppp/active/print');
$printRequest->setTag('p');
$client->sendAsync($printRequest, function($response) {
    if (preg_match('/^172\./', $response->getArgument('address')) {
        //Match
    }
});
$client->loop();  

[edit]Yeah, my bad… Although router-side regex filtering is not possible with the protocol, there is some other filtering with queries. You can check out this tutorial for details on how they’re done with my client.[/edit]

for some router side filtering you can see this:

http://wiki.mikrotik.com/wiki/Manual:API#Queries

so, some filtering is possible.