I have an array, and I would like to select one specif value from it.
I have a function that retrieves some api data and puts in in an this array.
The function is as follows;
function get_patronapi_data($id) {
$apiurl = APISERVER . "/PATRONAPI/$id/dump";
$api_contents = get_api_contents($apiurl); //get_api_contents() is a seperate function
$api_array_lines = explode("\n", $api_contents);
foreach ($api_array_lines as $key => $api_line) {
$api_line_arr = explode("=", $api_line);
$regex_match = array("/\[(.*?)\]/","/\s/","/#/");
$regex_replace = array('','','NUM');
$key = trim(preg_replace($regex_match, $regex_replace, $api_line_arr[0]));
$api_data[$key] = trim($api_line_arr[1]);
}
return $api_data;
}
$return_value = get_patronapi_data($id);
When I var_dump($api_array_lines) I get the following;
array(38) {
[0]=>
string(14) "REC INFO[p!]=p"
[1]=>
string(22) "EXP DATE[p43]=31-12-19"
[2]=>
string(13) "PCODE1[p44]=-"
[3]=>
string(13) "PCODE2[p45]=-"
[4]=>
string(14) "PCODE3[p46]=58"
[5]=>
string(14) "P TYPE[p47]=10"
[6]=>
string(17) "TOT CHKOUT[p48]=0"
[7]=>
string(17) "TOT RENWAL[p49]=0"
[8]=>
string(17) "CUR CHKOUT[p50]=0"
[9]=>
string(26) "BIRTH DATE[p51]= - -19 "
[10]=>
string(20) "HOME LIBR[p53]=qm "
[11]=>
string(15) "PMESSAGE[p54]=-"
[12]=>
string(13) "MBLOCK[p56]=-"
[13]=>
string(15) "REC TYPE[p80]=p"
[14]=>
string(21) "RECORD #[p81]=1083177"
[15]=>
string(17) "REC LENG[p82]=300"
[16]=>
string(21) "CREATED[p83]=01-10-12"
[17]=>
string(21) "UPDATED[p84]=08-10-15"
[18]=>
string(19) "REVISIONS[p85]=1091"
[19]=>
string(13) "AGENCY[p86]=1"
[20]=>
string(15) "CL RTRND[p95]=0"
[21]=>
string(22) "MONEY OWED[p96]=£0.00"
[22]=>
string(17) "CUR ITEMA[p102]=0"
[23]=>
string(17) "CUR ITEMB[p103]=0"
[24]=>
string(18) "ILL REQUES[p122]=0"
[25]=>
string(17) "CUR ITEMC[p124]=0"
[26]=>
string(17) "CUR ITEMD[p125]=0"
[27]=>
string(25) "CIRCACTIVE[p163]=08-10-15"
[28]=>
string(19) "NOTICE PREF[p268]=-"
[29]=>
string(34) "PATRN NAME[pn]=Smith, Mr Jo"
[30]=>
string(31) "PATRN NAME[pn]=Smith, Jo"
[31]=>
string(69) "ADDRESS[pa]=IT"
[32]=>
string(18) "TELEPHONE[pt]=6167865"
[33]=>
string(21) "UNIQUE ID[pu]=678678678"
[34]=>
string(21) "P BARCODE[pb]=456456"
[35]=>
string(22) "P BARCODE[pb]=345345"
[36]=>
string(33) "EMAIL ADDR[pz][email protected]"
[37]=>
string(12) "TITLE[pe]=Mr"
}
The only value I require from the array is EXP DATE (everything after the = sign) - this value is not always at position [1] - how can I select only this value?
Does it require additional regex or does my function need changed?
I must say I didn't write the above code I got it from here.
Quite new to php here and teaching myself so any help is greatly appreciated.