As I am trying to read the mt940 file from ING with help of https://github.com/fruitl00p/php-mt940 I tried his test file. it returns like this.
array(1) { [0]=> object(Kingsquare\Banking\Statement)#4 (9) {
["bank":"Kingsquare\Banking\Statement":private]=> string(3) "ING"
["account":"Kingsquare\Banking\Statement":private]=> string(9) "111111111"
["transactions":"Kingsquare\Banking\Statement":private]=> array(3) {
[0]=> object(Kingsquare\Banking\Transaction)#5 (9) {
["account":"Kingsquare\Banking\Transaction":private]=> string(9) "111111111"
["accountName":"Kingsquare\Banking\Transaction":private]=> string(34) "V. DE JONG KERKSTRAAT 1154 1234 BW"
["price":"Kingsquare\Banking\Transaction":private]=> float(0.56)
["debitcredit":"Kingsquare\Banking\Transaction":private]=> string(1) "C"
["cancellation":"Kingsquare\Banking\Transaction":private]=> bool(false)
["description":"Kingsquare\Banking\Transaction":private]=> string(128) "0111111111 V. DE JONG KERKSTRAAT 1154 1234 BWENSCHEDE BET.KENM. 1004510036716378 3305330802AFLOSSINGSTERMIJN 188616 / 1E TERMIJN"
["valueTimestamp":"Kingsquare\Banking\Transaction":private]=> int(1279737000)
["entryTimestamp":"Kingsquare\Banking\Transaction":private]=> int(1279737000)
["transactionCode":"Kingsquare\Banking\Transaction":private]=> string(3) "078" }
[1]=> object(Kingsquare\Banking\Transaction)#6 (9) {
["account":"Kingsquare\Banking\Transaction":private]=> string(9) "111111111"
["accountName":"Kingsquare\Banking\Transaction":private]=> string(25) "CUSTOMER NL SPOEDBETALING"
["price":"Kingsquare\Banking\Transaction":private]=> float(10.45)
["debitcredit":"Kingsquare\Banking\Transaction":private]=> string(1) "C" [
"cancellation":"Kingsquare\Banking\Transaction":private]=> bool(false)
["description":"Kingsquare\Banking\Transaction":private]=> string(120) "0111111111 CUSTOMER NL SPOEDBETALINGGE2009120212345RE0912023737 /RFB/NLFMI021209 NLFMI021209VOORSCHOTCOMMISSIE" ["valueTimestamp":"Kingsquare\Banking\Transaction":private]=> int(1279737000)
["entryTimestamp":"Kingsquare\Banking\Transaction":private]=> int(1279737000)
["transactionCode":"Kingsquare\Banking\Transaction":private]=> string(3) "077" }
}
["startPrice":"Kingsquare\Banking\Statement":private]=> float(44.89)
["endPrice":"Kingsquare\Banking\Statement":private]=> float(-9945.09)
["startTimestamp":"Kingsquare\Banking\Statement":private]=> int(1279737000)
["endTimestamp":"Kingsquare\Banking\Statement":private]=> int(1279823400)
["number":"Kingsquare\Banking\Statement":private]=> string(3) "100"
["currency":"Kingsquare\Banking\Statement":private]=> string(3) "EUR" } }
Here it returns with 'Kingsquare\Banking\Statement'. How do i remove that from entries results and how do I get the 'bank' , 'account', startprice, endprice and currency from the returned result.
here is the php program i have tried.
require 'vendor/autoload.php';
$parser = new \Kingsquare\Parser\Banking\Mt940();
$tmpFile = __DIR__ . '/test.mta';
$trans = $parser->parse(file_get_contents($tmpFile));
var_dump($trans);
You have those namespaces because you are dumping the varialbe out, to get the value you need just use the getter functions provided by Statement class:
$statement = $parser->parse(file_get_contents($tmpFile));
echo $statement[0]->getBank();
echo $statement[0]->getAccount();
echo $statement[0]->getStartPrice();
echo $statement[0]->getEndPrice();
echo $statement[0]->getCurrency();
Related
This question already has answers here:
How can i list has same id data with while loop in PHP? [closed]
(1 answer)
php get unique sub array [duplicate]
(1 answer)
Closed 4 years ago.
been using most of the day to solve my problem - and i am about to give up.
I have an array looking like this:
array(2) {
[1]=>
array(5) {
[0]=>
array(6) {
["name"]=>
string(15) "Henning smaall"
["drivernumber"]=>
string(4) "8830"
["period_start"]=>
string(10) "2018-07-20"
["period_end"]=>
string(10) "2018-07-31"
["status"]=>
string(1) "0"
["note"]=>
string(9) "Operation"
}
[1]=>
array(6) {
["name"]=>
string(15) "Henning smaall"
["drivernumber"]=>
string(4) "8830"
["period_start"]=>
string(10) "2018-07-17"
["period_end"]=>
string(10) "2018-07-17"
["status"]=>
string(1) "0"
["note"]=>
string(0) ""
}
[2]=>
array(6) {
["name"]=>
string(15) "Henning smaall"
["drivernumber"]=>
string(4) "8830"
["period_start"]=>
string(10) "2018-07-16"
["period_end"]=>
string(10) "2018-07-16"
["status"]=>
string(1) "1"
["note"]=>
string(0) ""
}
[3]=>
array(6) {
["name"]=>
string(15) "Henning smaall"
["drivernumber"]=>
string(4) "8830"
["period_start"]=>
string(10) "2018-07-27"
["period_end"]=>
string(10) "2018-07-27"
["status"]=>
string(1) "0"
["note"]=>
string(0) ""
}
[4]=>
array(6) {
["name"]=>
string(15) "Henning smaall"
["drivernumber"]=>
string(4) "8830"
["period_start"]=>
string(10) "2018-07-31"
["period_end"]=>
string(10) "2018-07-31"
["status"]=>
string(1) "1"
["note"]=>
string(0) ""
}
}
[13]=>
array(2) {
[0]=>
array(6) {
["name"]=>
string(15) "Henrik Hjersing"
["drivernumber"]=>
string(4) "8850"
["period_start"]=>
string(10) "2018-07-10"
["period_end"]=>
string(10) "2018-07-24"
["status"]=>
string(1) "0"
["note"]=>
string(0) ""
}
[1]=>
array(6) {
["name"]=>
string(15) "Henrik Hjersing"
["drivernumber"]=>
string(4) "8850"
["period_start"]=>
string(10) "2018-07-18"
["period_end"]=>
string(10) "2018-08-01"
["status"]=>
string(1) "0"
["note"]=>
string(11) "asdasdasdad"
}
}
}
The output i am looking for should be something like
Henning smaall (8830)
2018-07-20 - 2018-07-31
2018-07-17 - 2018-07-17
2018-07-16 - 2018-07-16
2018-07-27 - 2018-07-27
2018-07-31 - 2018-07-31
Henrik Hjersing (8850)
2018-07-10 - 2018-07-24
2018-07-18 - 2018-08-01
For now i am using dummy data and easy php testcode - but i keep getting the name reccuring in the output.
Database function:
public function resultsetGroup(){
$this->execute();
return $this->stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
}
SQL function:
public function getVacations(){
//$this->db->query('SELECT * FROM vacation ORDER BY user_id, status, period_start');
$this->db->query('SELECT u.id, u.name, u.drivernumber, v.period_start, v.period_end, v.status, v.note FROM users u, vacation v where u.id = v.user_id');
$results = $this->db->resultsetGroup();
return $results;
}
This is the php code i've been trying to alter in 500 different ways, and still i cannot get the result i am after - if i do not pdo group by u.id but u.name - it works, but then again, 2 people can have the same name - and that will break my intention.
<?php var_dump($data['vacations']); ?>
<?php foreach($data['vacations'] as $key => $vac) : ?>
<?php echo $key; ?>
<?php foreach($vac as $va) : ?>
<?php echo key($vac);?>
<h1><?php echo $va['name'] ?></h1>
<?php endforeach ; ?>
<?php endforeach ; ?>
Can you pls help me out? i feel like im running around in cirkles.
enter code here
Try this:
$vacations = array();
foreach($data['vacations'] as $key => $value){
foreach($value as $index => $person){
$vacations[$person['drivernumber']] = array();
$vacations[$person['drivernumber']]['name'] = $person['name'];
$vacations[$person['drivernumber']]['drivenumber'] = $person['drivenumber'];
$vacations[$person['drivernumber']]['vacations'] = "";
}
}// With this, you will have the array $vacations with the drivernumbers as keys without duplicates and initialized the name, drivenumber and vacations string.
foreach($data['vacations'] as $key => $value){
foreach($value as $index => $person){
$vacations[$person[drivenumber]]['vacations'] += $person['period_start'] . "-" . $person['period_end'] . " ";
}
}//This will concatenate all the period_start and period_end of each person in their respective position in the array.
foreach($vacations as $key => $value){
echo $value['name'] . " " . $value['drivernumber'] . " " . $value['vacations'];
}//Finally.. print in the format that you are requesting.
Please try.
I am using the PHP specific SOAPClient in order to call for a soap API and get responses.
The problem I have is that I do not manage to get in order the results, neither to extract them.
The code I am using is:
<?php
$wsdl = 'http://portalquery.just.ro/Query.asmx?wsdl';
$client = new SoapClient($wsdl);
$xml_array['numarDosar'] = '10080/3/2013';
$response = $client->CautareDosare2($xml_array);
var_dump($response);
?>
The results I get are:
object(stdClass)#2 (1) { ["CautareDosare2Result"]=> object(stdClass)#3 (1) { ["Dosar"]=> array(2) { [0]=> object(stdClass)#4 (13) { ["parti"]=> object(stdClass)#5 (1) { ["DosarParte"]=> array(3) { [0]=> object(stdClass)#6 (2) { ["nume"]=> string(22) "Mocanu Andrei Cristian" ["calitateParte"]=> string(17) "Recurent Inculpat" } [1]=> object(stdClass)#7 (2) { ["nume"]=> string(21) "Mocanu Răzvan George" ["calitateParte"]=> string(17) "Recurent Inculpat" } [2]=> object(stdClass)#8 (2) { ["nume"]=> string(11) "Mica Marian" ["calitateParte"]=> string(17) "Recurent Inculpat" } } } ["sedinte"]=> object(stdClass)#9 (1) { ["DosarSedinta"]=> object(stdClass)#10 (9) { ["complet"]=> string(26) "S2 Complet urgentă recurs" ["data"]=> string(19) "2013-03-14T00:00:00" ["ora"]=> string(5) "12:00" ["solutie"]=> string(14) "Respins recurs" ["solutieSumar"]=> string(408) "Înc. 82/R/În majoritate :Respinge ca nefondate recursurile declararate de recurenţii inculpaţi Mocanu Andrei Cristian, Mocanu Răzvan George şi Mica Marian. Obligă pe fiecare recurent la câte 300 lei cheltuieli judiciare către stat. Pronunţată în şedinţă publică, azi, 14.03.2013. Opinie separată în sensul admiterii recursurilor şi luării măsurii obligării de a nu părăsi localitatea." ["dataPronuntare"]=> string(19) "2013-03-14T00:00:00" ["documentSedinta"]=> string(33) "incheieremasuripreventivefazadeUP" ["numarDocument"]=> string(7) "82/2013" ["dataDocument"]=> string(19) "2013-03-14T00:00:00" } } ["numar"]=> string(12) "10080/3/2013" ["numarVechi"]=> string(8) "831/2013" ["data"]=> string(19) "2013-03-14T00:00:00" ["institutie"]=> string(21) "CurteadeApelBUCURESTI" ["departament"]=> string(22) "Secţia a II-a penală" ["categorieCaz"]=> string(5) "Penal" ["stadiuProcesual"]=> string(6) "Recurs" ["obiect"]=> string(113) "prelungirea duratei arestării preventive dispuse în cursul urmăririi penale (art. 156 şi următoarele C.p.p.)" ["dataModificare"]=> string(23) "2017-01-18T06:48:34.467" ["categorieCazNume"]=> string(5) "Penal" ["stadiuProcesualNume"]=> string(6) "Recurs" } [1]=> object(stdClass)#11 (14) { ["parti"]=> object(stdClass)#12 (1) { ["DosarParte"]=> array(3) { [0]=> object(stdClass)#13 (2) { ["nume"]=> string(22) "MOCANU ANDREI CRISTIAN" ["calitateParte"]=> string(8) "Inculpat" } [1]=> object(stdClass)#14 (2) { ["nume"]=> string(20) "MOCANU RAZVAN GEORGE" ["calitateParte"]=> string(8) "Inculpat" } [2]=> object(stdClass)#15 (2) { ["nume"]=> string(11) "MICA MARIAN" ["calitateParte"]=> string(8) "Inculpat" } } } ["sedinte"]=> object(stdClass)#16 (1) { ["DosarSedinta"]=> object(stdClass)#17 (9) { ["complet"]=> string(5) "CC1 -" ["data"]=> string(19) "2013-03-12T00:00:00" ["ora"]=> string(5) "23:59" ["solutie"]=> string(12) "Soluţionare" ["solutieSumar"]=> string(311) "În baza prevederilor art. 155 şi urm. C.p.p. dispune prelungirea măsurii arestării preventive a inculpaţilor Mocanu Andrei Cristian, Mocanu Răzvan George şi Mica Marius pe o perioadă de 20 de zile, de la 15.03.2013 - 03.04.2013, inclusiv. Cu recurs. Pronunţată în şedinţă publică azi, 12.03.2013." ["dataPronuntare"]=> string(19) "2013-03-12T00:00:00" ["documentSedinta"]=> string(27) "incheierefinaladezinvestire" ["numarDocument"]=> string(0) "" ["dataDocument"]=> string(19) "2013-03-12T00:00:00" } } ["caiAtac"]=> object(stdClass)#18 (1) { ["DosarCaleAtac"]=> object(stdClass)#19 (3) { ["dataDeclarare"]=> string(19) "2013-03-13T00:00:00" ["parteDeclaratoare"]=> string(37) " MICA MARIAN, MOCANU RAZVAN GEORGE, " ["tipCaleAtac"]=> string(6) "Recurs" } } ["numar"]=> string(12) "10080/3/2013" ["numarVechi"]=> string(0) "" ["data"]=> string(19) "2013-03-11T00:00:00" ["institutie"]=> string(19) "TribunalulBUCURESTI" ["departament"]=> string(22) "Secţia a-II-a Penală" ["categorieCaz"]=> string(5) "Penal" ["stadiuProcesual"]=> string(4) "Fond" ["obiect"]=> string(113) "prelungirea duratei arestării preventive dispuse în cursul urmăririi penale (art. 156 şi următoarele C.p.p.)" ["dataModificare"]=> string(23) "2017-01-18T08:33:50.877" ["categorieCazNume"]=> string(5) "Penal" ["stadiuProcesualNume"]=> string(4) "Fond" } } } }
I tried to explode on the results, also used $response[1]->array and such, nothing works.
<?php
ini_set("display_errors", 1);
$wsdl = 'http://portalquery.just.ro/Query.asmx?wsdl';
$client = new SoapClient($wsdl);
$xml_array['numarDosar'] = '10080/3/2013';
$response = $client->CautareDosare2($xml_array);
$resultArray= json_decode(json_encode($response),true);
$arrayOnfirstKey=$resultArray[key($resultArray)];
$arrayOnSecondKey= $arrayOnfirstKey[key($arrayOnfirstKey)];
echo "<table>";
echo "<tr>";
echo "<td>nume</td>";
echo "<td>CalitateParte</td>";
echo "</tr>";
foreach($arrayOnSecondKey as $value)
{
foreach($value["parti"]["DosarParte"] as $data)
{
echo "<tr>";
echo "<td>" .$data["nume"]."</td>";
echo "<td>" .$data["calitateParte"]."</td>";
echo "</tr>";
}
}
echo "</table>";
I want to parse JSON that I recieve from steam via api link http://steamcommunity.com/id/theorangeass/inventory/json/753/1/ , but when I try to print it with echo it show nothing.
Here is the code
$data = file_get_contents('http://steamcommunity.com/id/theorangeass/inventory/json/753/1/');
$json = json_decode($data, true);
echo $json->success;
var_dump:
array(6) { ["success"]=> bool(true) ["rgInventory"]=> array(1) { ["922506184369981039"]=> array(5) { ["id"]=> string(18) "922506184369981039" ["classid"]=> string(10) "1254492673" ["instanceid"]=> string(10) "2070301907" ["amount"]=> string(1) "1" ["pos"]=> int(1) } } ["rgCurrency"]=> array(0) { } ["rgDescriptions"]=> array(1) { ["1254492673_2070301907"]=> array(18) { ["appid"]=> string(3) "753" ["classid"]=> string(10) "1254492673" ["instanceid"]=> string(10) "2070301907" ["icon_url"]=> string(116) "U8721VM9p9C2v1o6cKJ4qEnGqnE7IoTQgZI-VTdwyTBeimAcIowbqB-harb00cJ0fNdiCJoFB3O541FNc9ZPYXYjjL7UqfFEwOtgZKcs0eWlClqzSJn6" ["icon_url_large"]=> string(106) "U8721VM9p9C2v1o6cKJ4qEnGqnE7IoTQgZI-VTdwyTBeimAcIowbqB-harb00cJ0fNdiA54UEGOnqGQPJ9hDZHA50feEo7RMyO_GQNzkkA" ["icon_drag_url"]=> string(0) "" ["name"]=> string(4) "BEEP" ["market_name"]=> string(0) "" ["name_color"]=> string(0) "" ["background_color"]=> string(0) "" ["type"]=> string(4) "Gift" ["tradable"]=> int(0) ["marketable"]=> int(0) ["commodity"]=> int(0) ["cache_expiration"]=> string(20) "2017-01-02T00:00:00Z" ["fraudwarnings"]=> array(1) { [0]=> string(223) "This is a restricted gift which can only be redeemed in these countries: Armenia, Azerbaijan, Belarus, Georgia, Kyrgyzstan, Kazakhstan, Moldova, Republic of, Tajikistan, Turkmenistan, Uzbekistan, Ukraine, Russian Federation" } ["descriptions"]=> array(1) { [0]=> array(1) { ["value"]=> string(216) "A combination of Yoshi’s Island-style platforming with a gravity gun right out of Half-Life, BEEP is an amazing physics-platformer. Despite its friendly art style, this is a hardcore platformer in the truest sense." } } ["actions"]=> array(1) { [0]=> array(2) { ["name"]=> string(13) "View in store" ["link"]=> string(41) "http://store.steampowered.com/app/104200/" } } } } ["more"]=> bool(false) ["more_start"]=> bool(false) }
You are trying to echo a boolean. If you are wanting to echo true you're going to need to do an if, or a switch statement. An if statement would probably be easiest.
echo $json->success == true ? 'TRUE' : 'FALSE';
To parse the array to retrieve the item id's in the rgInventory to must do a foreach.
foreach ($json['rgInventory'] as $item) {
echo $item['id'];
}
Where you should start learning about arrays is Here
i want to create an php array from an xml-file like this
test.xml
object(SimpleXMLElement)#3 (2) { ["uebertragung"]=> object(SimpleXMLElement)#5 (1) { ["#attributes"]=> array(9)
{ ["art"]=> string(7) "OFFLINE" ["umfang"]=> string(4) "TEIL"
["modus"]=> string(3) "NEW" ["version"]=> string(5) "1.2.7" ["sendersoftware"]=> string(7) "crm11" ["senderversion"]=> string(3) "1.1"
["techn_email"]=> string(18) "support#mail.com" ["timestamp"]=> string(19)
"2014-06-01T10:00:00" ["regi_id"]=> string(7) "ABCD143" } }
["anbieter"]=> object(SimpleXMLElement)#4 (3) { ["anbieternr"]=>
string(6) "144185" ["firma"]=> string(14) "redfirm"
["immobilie"]=> object(SimpleXMLElement)#6 (7) { ["objektkategorie"]=> object(SimpleXMLElement)#7 ...
mycode:
$xml = simplexml_load_file("test.xml") or die("Error: Cannot read xml file");
var_dump($xml);
echo "show1: " .$xml->openimmo->uebertragung->{'art'} . "<br>";
echo "show2: " .$xml->openimmo->uebertragung['art'];
show 1+2 show nothing, can someone help me, i dont understand the array structure ?
The art is an attribute, so you can get its value by
$xml->openimmo->uebertragung->attributes()->art
More here
http://php.net/manual/en/simplexmlelement.attributes.php
I am obtaining a json object using the following:
$json = file_get_contents("url-here");
$data = json_decode($json, true);
//test
var_dump($data);
This gives me something like this:
array(2) { ["ok"]=> bool(true) ["result"]=> array(1) { [0]=> array(2)
{ ["update_id"]=> int(44893465) ["message"]=> array(5) {
["message_id"]=> int(16) ["from"]=> array(3) { ["id"]=> int(29595794)
["first_name"]=> string(3) "Bob" ["username"]=> string(14) "Bobo" }
["chat"]=> array(3) { ["id"]=> int(29595794) ["first_name"]=>
string(3) "Bob" ["username"]=> string(14) "Bobo" } ["date"]=>
int(1435354253) ["text"]=> string(7) "/q 3.33" } } } }
I would then like to add certain values into variables. For example I would like to extract username, text, message_id, etc
But no matter what I try my variables are empty:
//let's test it
echo "Username: " . $data[1][0]["username"];
//another test
echo $data->username;
Neither of these are working and my research has not helped me find a solution. I am stumped on this one.
Any pointers in the right direction would really be appreciated.
array(2) {
["ok"]=> bool(true)
["result"]=> array(1)
{
[0]=> array(2)
{
["update_id"]=> int(44893465)
["message"]=> array(5)
{
["message_id"]=> int(16)
["from"]=> array(3)
{
["id"]=> int(29595794)
["first_name"]=> string(3) "Bob"
["username"]=> string(14) "Bobo"
}
["chat"]=> array(3)
{
["id"]=> int(29595794)
["first_name"]=> string(3) "Bob"
["username"]=> string(14) "Bobo"
}
["date"]=> int(1435354253)
["text"]=> string(7) "/q 3.33"
}
}
}
}
You are using wrong array index. $data[1][0]["username"]; not exists.
$data["result"][0]["message"]["from"]["username"];
$data["result"][0]["message"]["chat"]["username"];
This will give you the proper username
$json = file_get_contents("url-here");
$data = json_decode($json, true);
//test
echo $data["result"][0]['message']['from']['username'];
output
Bobo