如何过滤脚本的输出?

I have a node script that fetches all the peers. Can I filter that output using php?

I mean I dont need all the peers fetched by that script, so can i just get some specific peers using functions like strcmp? Currently my node script outputs the result in an html page. But I want it to be printed on php page with filter applied to it.

You can check lines of output one-by-one and use strpos or regexp searching functions(pref_match etc)

You also can list only some peers using construction

sip show peers like something

Technically speaking, you can do that. I would assume that your script is using the Asterisk "-rx" parameter to achieve this. Personally, that is a none reliable solution, I've seen situations in the past where running a command while "-rx", while within a script will yield no result.

My suggestion to you is to use something like PHPAGI and connect directly to the Asterisk Manager (AMI) and obtain the information from there. The solution will include less moving parts and will most surely be more reliable.