$cm_json = exec('curl -H "Accept: application/vnd.pagerduty+json;version=2" -H "Authorization: Token token="XXXXXXX" -X GET -G "https://api.pagerduty.com/users/'.$user_id.'/contact_methods/" | jq '.contact_methods[] | select(.label == "Mobile") | .address'');
PHP解析错误:语法错误,第56行出现意外的'['
答案 0 :(得分:0)
您遇到报价问题。在jq过滤器的单引号前使用baskslash:
$cm_json = exec('curl -H "Accept: application/vnd.pagerduty+json;version=2" -H "Authorization: Token token="XXXXXXX" -X GET -G "https://api.pagerduty.com/users/'.$user_id.'/contact_methods/" | jq \'.contact_methods[] | select(.label == "Mobile") | .address\'');