0

The issues I am having is I have not written php in some time and I am not sure what this output is. It looks like multiple arrays but when I try different code techniques I get different errors. This is an API for a piece of software I use.


[{"id": 1, "admin_state": 2, "sub_type": "realtime", "imsi": "001001000000000", "tmsi": "", "ptmsi": "00002fec", "imei": "352204110101575", "msisdn": "8103", "authorised": 1, "privilege_level": 0, "sip_client_attachment": "DETACHED", "mno_attachment": "DETACHED", "local_ps_attachment": "DETACHED", "mno_ps_attachment": "DETACHED", "lac": 0, "previous_lac": 0, "tac": 1, "domain": "127.0.0.1", "ki": "RAE$3TMuESn8xDNnXGhoXWJN3aYEeNouU6fpP4xjhs1RqdLui3B6RhtVZ4fMQQwOLaSz", "sip_username": "8103", "sip_password": "RAE$/Z5sYuObIlUdRlG5ep3JsA==", "auth_algorithm": "milenage", "ciphering_algorithm": "best", "cell_id": 25600, "name": "Fan Pi", "additional_info": "Test SIM", "call_forward_unconditional": "", "call_forward_on_busy": "", "call_forward_on_no_answer": "", "call_forward_on_out_of_reach": "", "call_forward_condition_time": 0, "welcome_sms_sent": 0, "sip_profile_id": 2, "mt_sip_profile_id": 0, "user_portal_username": "", "last_mwi": 0, "opc": "RAE$2CEXaWZv0kcRx+/v1hguzyiduxQr+G0FQCtSYOl9J4wdMObPx5jMYkvJVX2vFiyL", "measurement_record_interval": 1, "priority": 0, "dl_ambr": 500000, "ul_ambr": 500000, "mno_cs_activity_time": "", "mno_ps_activity_time": "", "classmark1": 0, "nas_encryption": 0, "local_cs_activity_time": "", "local_ps_activity_time": "", "last_call_divert_status": 0, "short_network_name": "", "call_divert_sms_prefix": "", "wifi_enabled": 1, "record_measurements": 0, "vlr_number": "", "msc_number": "", "sgsn_number": "", "mme_number": "", "mme_host": "", "mme_realm": "", "sip_client_detach_time": "", "telephony_allowed": 1, "emergency_calls_allowed": 1, "mt_sms_allowed": 1, "mo_sms_allowed": 1, "visitor": 0, "digest_aka_supported": 0, "terminate_pdp_context_req": 0, "force_camping": 0, "subscription_profile_preference_id": 0, "csg_ids": "", "ran_type": 2, "enodeb_id": 25600, "gnb_id": 0, "odb_all_packet_services_barred": 0, "odb_all_out_calls_barred": 0, "odb_out_int_calls_barred": 0, "odb_out_int_calls_hplmn_barred": 0} ,{"id": 2, "admin_state": 2, "sub_type": "realtime", "imsi": "001001000000001", "tmsi": "", "ptmsi": "", "imei": "", "msisdn": "8104", "authorised": 1, "privilege_level": 0, "sip_client_attachment": "DETACHED", "mno_attachment": "DETACHED", "local_ps_attachment": "DETACHED", "mno_ps_attachment": "DETACHED", "lac": 0, "previous_lac": 0, "tac": 0, "domain": "127.0.0.1", "ki": "RAE$lZv74E2b806SJXR59ZQPTxZyv/3KLYuE3H78CBNroq5Ofe+3f7/5wDPbgSq5tQyj", "sip_username": "iPhone", "sip_password": "RAE$Ti+ahShFJo7CBuIfLXG5ow==", "auth_algorithm": "milenage", "ciphering_algorithm": "best", "cell_id": 258, "name": "iPHONE", "additional_info": "PCS iPhone 11", "call_forward_unconditional": "", "call_forward_on_busy": "", "call_forward_on_no_answer": "", "call_forward_on_out_of_reach": "", "call_forward_condition_time": 0, "welcome_sms_sent": 0, "sip_profile_id": 2, "mt_sip_profile_id": 0, "user_portal_username": "", "last_mwi": 0, "opc": "RAE$o2hAK59veuo/zkg1mZL0EsWRtcXX2E73hL/YbkrHtG+zhqH0nHCzbd2f2ykiDKiV", "measurement_record_interval": 1, "priority": 1, "dl_ambr": 500000, "ul_ambr": 500000, "mno_cs_activity_time": "", "mno_ps_activity_time": "", "classmark1": 0, "nas_encryption": 0, "local_cs_activity_time": "", "local_ps_activity_time": "", "last_call_divert_status": 0, "short_network_name": "", "call_divert_sms_prefix": "", "wifi_enabled": 1, "record_measurements": 0, "vlr_number": "", "msc_number": "", "sgsn_number": "", "mme_number": "", "mme_host": "", "mme_realm": "", "sip_client_detach_time": "", "telephony_allowed": 1, "emergency_calls_allowed": 1, "mt_sms_allowed": 1, "mo_sms_allowed": 1, "visitor": 0, "digest_aka_supported": 0, "terminate_pdp_context_req": 0, "force_camping": 0, "subscription_profile_preference_id": 0, "csg_ids": "", "ran_type": 0, "enodeb_id": 1, "gnb_id": 0, "odb_all_packet_services_barred": 0, "odb_all_out_calls_barred": 0, "odb_out_int_calls_barred": 0, "odb_out_int_calls_hplmn_barred": 0} ,{"id": 3, "admin_state": 2, "sub_type": "realtime", "imsi": "001001000000002", "tmsi": "", "ptmsi": "", "imei": "", "msisdn": "8105", "authorised": 1, "privilege_level": 0, "sip_client_attachment": "DETACHED", "mno_attachment": "DETACHED", "local_ps_attachment": "DETACHED", "mno_ps_attachment": "DETACHED", "lac": 0, "previous_lac": 0, "tac": 0, "domain": "127.0.0.1", "ki": "RAE$truYilo4PX9AXtXeFbwXSjDIT9SDX/Qhkg2lHq9OH8ltSJnWY7O81WOzUfNarxYB", "sip_username": "matt", "sip_password": "RAE$Ti+ahShFJo7CBuIfLXG5ow==", "auth_algorithm": "milenage", "ciphering_algorithm": "best", "cell_id": 0, "name": "Matt", "additional_info": "", "call_forward_unconditional": "", "call_forward_on_busy": "", "call_forward_on_no_answer": "", "call_forward_on_out_of_reach": "", "call_forward_condition_time": 0, "welcome_sms_sent": 0, "sip_profile_id": 2, "mt_sip_profile_id": 0, "user_portal_username": "", "last_mwi": 0, "opc": "RAE$fidD+0Z9Z3+ExqDJHFKzbETKiYb0up4urEeWS1n6aot3Nav168szpQfA5x4H+Kh6", "measurement_record_interval": 1, "priority": 0, "dl_ambr": 500000, "ul_ambr": 500000, "mno_cs_activity_time": "", "mno_ps_activity_time": "", "classmark1": 0, "nas_encryption": 0, "local_cs_activity_time": "", "local_ps_activity_time": "", "last_call_divert_status": 0, "short_network_name": "", "call_divert_sms_prefix": "", "wifi_enabled": 1, "record_measurements": 0, "vlr_number": "", "msc_number": "", "sgsn_number": "", "mme_number": "", "mme_host": "", "mme_realm": "", "sip_client_detach_time": "", "telephony_allowed": 1, "emergency_calls_allowed": 1, "mt_sms_allowed": 1, "mo_sms_allowed": 1, "visitor": 0, "digest_aka_supported": 0, "terminate_pdp_context_req": 0, "force_camping": 0, "subscription_profile_preference_id": 0, "csg_ids": "", "ran_type": 0, "enodeb_id": 0, "gnb_id": 0, "odb_all_packet_services_barred": 0, "odb_all_out_calls_barred": 0, "odb_out_int_calls_barred": 0, "odb_out_int_calls_hplmn_barred": 0} ,{"id": 5, "admin_state": 2, "sub_type": "realtime", "imsi": "001001000000004", "tmsi": "", "ptmsi": "00000c4b", "imei": "352204110101229", "msisdn": "8107", "authorised": 1, "privilege_level": 0, "sip_client_attachment": "DETACHED", "mno_attachment": "DETACHED", "local_ps_attachment": "DETACHED", "mno_ps_attachment": "DETACHED", "lac": 0, "previous_lac": 0, "tac": 1, "domain": "127.0.0.1", "ki": "RAE$AjAAppiV77ha42WruvqfHMBQz2L3yZm+5fUGVbB7lDcdka5VKR9epBy3iVkeUpIR", "sip_username": "", "sip_password": "RAE$Ti+ahShFJo7CBuIfLXG5ow==", "auth_algorithm": "milenage", "ciphering_algorithm": "best", "cell_id": 51400, "name": "Video Pi", "additional_info": "", "call_forward_unconditional": "", "call_forward_on_busy": "", "call_forward_on_no_answer": "", "call_forward_on_out_of_reach": "", "call_forward_condition_time": 0, "welcome_sms_sent": 0, "sip_profile_id": 3, "mt_sip_profile_id": 0, "user_portal_username": "", "last_mwi": 0, "opc": "RAE$28q16oSoLhqR84euVGgy2Neg1NPCu6tVcT6T2c4HqMBt856A/Cw6WT7EpMiTzw+u", "measurement_record_interval": 1, "priority": 0, "dl_ambr": 500000, "ul_ambr": 500000, "mno_cs_activity_time": "", "mno_ps_activity_time": "", "classmark1": 0, "nas_encryption": 0, "local_cs_activity_time": "", "local_ps_activity_time": "", "last_call_divert_status": 0, "short_network_name": "", "call_divert_sms_prefix": "", "wifi_enabled": 1, "record_measurements": 0, "vlr_number": "", "msc_number": "", "sgsn_number": "", "mme_number": "", "mme_host": "", "mme_realm": "", "sip_client_detach_time": "", "telephony_allowed": 1, "emergency_calls_allowed": 1, "mt_sms_allowed": 1, "mo_sms_allowed": 1, "visitor": 0, "digest_aka_supported": 0, "terminate_pdp_context_req": 0, "force_camping": 0, "subscription_profile_preference_id": 0, "csg_ids": "", "ran_type": 2, "enodeb_id": 200, "gnb_id": 0, "odb_all_packet_services_barred": 0, "odb_all_out_calls_barred": 0, "odb_out_int_calls_barred": 0, "odb_out_int_calls_hplmn_barred": 0} ]

I have tried almost everything I could think of with help from Stackoverflow but everything returns an error. The code I am using for this is.

$obj = file_get_contents('http://raemis:password@192.168.100.2/api/subscriber');
echo $obj

I have done foreach, unset, etc and I can get close but cannot get it to just output the "msisdn" for each enrty.

Any help is greatly appreciated.

Matt Saiko
  • 31
  • 8
  • 1
    Read this: [How to extract and access data from JSON with PHP?](https://stackoverflow.com/questions/29308898/how-to-extract-and-access-data-from-json-with-php) – ADyson Aug 20 '22 at 00:34

1 Answers1

1

It looks like JSON.

You can access that output in PHP with json_decode().

Here is a PHPFiddle example.

The code is:

var_export(array_column(json_decode($json), 'msisdn'));

array_column() gets the msisdn column from the 2D array.

which generates this output:

array (
  0 => '8103',
  1 => '8104',
  2 => '8105',
  3 => '8107',
)
KIKO Software
  • 15,283
  • 3
  • 18
  • 33