Trying to decode php code from unknown format - php

I have this code (sample out of 24500 line code is provided below) in php language and I want to use this code in my project but problem is that, It is converted to unknown format.
$O = array( function($XB0) use (&$O)
{
$lej = array( 6323 => "sq", 1630 => "invalid_perfectmoney_account", 1462 => "Lebanon", 1867 => "/<br> Cash Passport Result URL - ", 261 => "alertpay_from_account", 5096 => " + interval 1 hour and deposit_id = ", 7651 => " group by t.id ", 845 => "select email from hm2_users where id = 1", 5952 => "Location: ", 9642 => "]", 3792 => "select username from hm2_users where id = ", 1591 => "update hm2_users set verify = 1 where id = " );
return $lej[$XB0];
}
, 289, 691, 561, 691, function($LBV) use (&$O)
{
$b4X = array( 1591 => "zero_amount", 3792 => "l dS of F Y h:i:s A", 1630 => "QXCR58Z29CNWP8GVKDXP", 1867 => "India", 845 => "Define Key String (random string)", 7651 => "actual_amount", 5096 => "k", 261 => "</ns1:Receiver> <ns1:Currency>", 5952 => ") as create_account_date, now() - interval 2 minute > l_e_t as should_count from hm2_users where ", 9642 => "update hm2_users set password = ", 1462 => "Romania", 6323 => ", ip_reg = ", 4683 => "qplans" );
return $b4X[$LBV];
}
, 515, 901, 487, 779, function($wjS, $I8j, $Sbx) use (&$O)
{
if( $I8j[$O[327](7651)] == $O[1299](7651) )
{
$S3J = 0;
print " ";
if( $I8j[$O[90](5096)] != "" )
{
$S3J = 1;
$O[703](7651);
print $O[703](7651);
$O[161](7651);
print $I8j[$O[161](7651)];
$O[1184](7651);
print $O[1184](7651);
$O[161](7651);
print $I8j[$O[161](7651)];
$O[478](5096);
print $O[478](5096);
}
$O[703](7651);
print $O[703](7651);
$O[161](7651);
print $I8j[$O[161](7651)];
$O[828](7651);
print $O[828](7651);
print ($S3J ? $O[814](7651) : "");
$O[39](7651);
print $O[39](7651);
$O[1043](7651);
print $I8j[$O[1043](7651)];
$O[194](5096);
print $O[194](5096);
$O[380]($I8j[$O[1016](7651)]);
print $O[380]($I8j[$O[1016](7651)]);
$O[99](5096);
print $O[99](5096);
if( $S3J )
{
$O[996](7651);
print $O[996](7651);
$O[1043](7651);
print $I8j[$O[1043](7651)];
$O[467](7651);
print $O[467](7651);
$O[161](7651);
print $I8j[$O[161](7651)];
$O[1244](5096);
print $O[1244](5096);
$O[161](7651);
print $I8j[$O[161](7651)];
$O[1236](7651);
print $O[1236](7651);
}
$O[1063](845);
print $O[1063](845);
}
else
{
if( $I8j[$O[327](7651)] == $O[582](5096) )
{
$O[1189](5096);
print $O[1189](5096);
$O[1043](7651);
print $I8j[$O[1043](7651)];
$O[103](7651);
print $O[103](7651);
$O[380](($I8j[$O[90](5096)] != "" ? $I8j[$O[90](5096)] : $I8j[$O[100](7651)]));
print $O[380](($I8j[$O[90](5096)] != "" ? $I8j[$O[90](5096)] : $I8j[$O[100](7651)]));
$O[536](7651);
print $O[536](7651);
$O[380]($I8j[$O[1016](7651)]);
print $O[380]($I8j[$O[1016](7651)]);
$O[446](7651);
print $O[446](7651);
}
else
{
if( $I8j[$O[327](7651)] == $O[793](7651) )
{
$O[965](5096);
print $O[965](5096);
$O[1043](7651);
print $I8j[$O[1043](7651)];
$O[888](7651);
print $O[888](7651);
foreach( $DSo as $lIx => $RdI )
{
print " ";
if( $RdI[$O[735](7651)] == 1 )
{
$O[327](5096);
print $O[327](5096);
print $lIx;
$O[937](5096);
print $O[937](5096);
$O[90](5096);
print ($lIx == $I8j[$O[90](5096)] ? $O[352](7651) : "");
$O[901](7651);
print $O[901](7651);
$O[1016](5096);
print $RdI[$O[1016](5096)];
$O[598](5096);
print $O[598](5096);
}
print " ";
}
$O[271](5096);
print $O[271](5096);
return NULL;
}
else
{
if( $I8j[$O[327](7651)] == $O[183](7651) )
{
$xb4 = $I8j[$O[183](7651)];
if( $xb4 )
{
$xb4($wjS, $I8j, $Sbx);
print $xb4($wjS, $I8j, $Sbx);
}
}
}
}
}
}
, 373, 154, function($x71) use (&$O)
{
$Bsd = array( 6357 => "min_user_password_length", 4683 => "\"/>", 3792 => "\"> <input type=hidden name=ureturn value=\"", 1462 => "~/[\\w\\d]+\\.php.*~", 9642 => "crate", 5952 => " to ", 261 => "last_pay_date", 5096 => "on", 7651 => "/_secret_key/", 845 => " from hm2_history group by user_id, ec", 1867 => "%.0", 1630 => "https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=", 6323 => "Purse", 1591 => "recipient", 2607 => "last_withdrawals", 2429 => "Russian Federation", 7210 => "use_transaction_code", 4186 => "2 weeks" );
return $Bsd[$x71];
}
I have two questions from it:
What php format is this code?
How to convert it back into readable format?
Thanks in advance..

Related

Print next array keys in array of arrays

I have an array of arrays that contain array key with the value, here the example :
Array (
[0] => Array ( [Hotel] => N [Jayakarta] => NE [Jaya] => NE [sangat] => ADV [nyaman] => ADJ [ditempati] => V. )
[1] => Array ( [Andi] => NOB [Hotel] => N [menginap] => V [disana] => N [selama] => N [satu] => NUM [minggu] => N. )
)
I want to make an output if I found a key of "Hotel" then I will print next key from "Hotel". For example :
Hotel Jayakarta Jaya
Hotel menginap disana
Here's what I am doing for the moment:
foreach($token2 as $index => $tok){
foreach ($tok as $tokkey => $tokvalue) {
if ($tokkey == "Hotel" and $tokvalue == "N"){
echo $tokkey . " " ;
while($cek == true && $x <= 2){
$next = next($tok);
echo key($tok). " " ;
$x++;
}
echo ", ";
$x = 1;
}
}
}
And the output :
Hotel Jayakarta jaya sangat , Hotel Hotel menginap
The Expected Output should be as below:
Hotel Jayakarta jaya sangat , Hotel menginap disana selama
Any help is much appreciated, Thank you.
Do something like following:
$i = 3;
foreach($token2 as $index => $tok){
foreach ($tok as $tokkey => $tokvalue) {
if ($tokkey == "Hotel" && $tokvalue == "N"){
echo $tokkey . " " ;
$i = 1;
}
else if($i < 3){
echo $tokkey . " ";
$i++;
}
}
echo ", ";
}
maybe you could try this ?
$arrayOfHotels = array(0 => array('Hotel' => 'N' , 'Jakarta' => 'NE', 'Jaya' => 'NE', 'sangat' => 'ADV', 'nyaman' => 'ADJ', 'ditempati' => 'V.'),1 => array('Andi' => 'NOB', 'Hotel' => 'N', 'menginap' => 'V', 'disana' => 'N', 'selama' => 'N', 'satu' => 'NUM', 'minggu' => 'N.'));
echo '<pre>';
print_r(findHotel($arrayOfHotels));
echo '</pre>';
function findHotel($hotels)
{
$isHotelFind = false;
$isFirstThrough = true;
foreach($hotels as $row => $value)
{
foreach ($value as $row2 => $value2)
{
if($row2 == "Hotel" && $value = 'N' && !$isHotelFind)
{
if($isFirstThrough)
{
echo $row2 . " ";
}
else
{
echo ", " . $row2 . " ";
}
$isHotelFind = true;
$isFirstThrough = false;
}
if($isHotelFind && $row2 != "Hotel")
{
echo $row2 . " ";
}
}
$isHotelFind = false;
}
}
You can use array_search to find your key and remove leading elements before it.
$array = [
[
"Hotel" => 'N',
"Jayakarta" => 'NE',
'Jaya' => 'NE',
'sangat' => 'ADV',
'nyaman' => 'ADJ',
'ditempati' => 'V.'
]
,
[
"Andi" => 'NOB',
"Hotel" => 'N',
'menginap' => 'V',
'disana' => 'N',
'selama' => 'N',
'satu' => 'NUM',
'minggu' => 'N.'
]
];
foreach ($array as $data) {
// Find index to start
$index = array_search("Hotel", array_keys($data));
// Remove other keys
$new_array_starting_hotel = array_splice($data, $index, count($data));
// merge results
$merged[] = implode(' ', array_keys($new_array_starting_hotel));
}
print_r($merged);
And output will be like:
Array
(
[0] => Hotel Jayakarta Jaya sangat nyaman ditempati
[1] => Hotel menginap disana selama satu minggu
)
You can merge or implode all however you like.

Query work in PhpMyAdmin but does not work in php code

if ($row_tow['wydane'] == 0){
$task="UPDATE zamowienia
SET status_zam=0, data_aktualizacji=NOW()
WHERE id_firmy='".$_SESSION["id_firmy"]."' AND nrzamowienia='".$row_tow['nrzamowienia']."'";
$mysqli->query($task);
}
That query changes only status_zam, but data_aktualizacji isn't updated.
Query works fine at phpmyadmin.
$results_tow = $mysqli->query("SELECT sum(ilosc_zlecona_kuchni) as ilosc_zlecona_kuchni, CURTIME() AS datateraz, nazwa_towaru, uwagi, dodatek, wydane, odebrane, TIME_FORMAT(godz, '%H:%i') AS godz, data_zam FROM `produkty` WHERE nrzamowienia='".$row['nrzamowienia']."' AND id_firmy='".$_SESSION["id_firmy"]."' AND DATA_ZAM = CURDATE() GROUP BY nrtowaru, dodatek, nazwa_towaru, uwagi, wydane, odebrane, godz");
if ($results_tow)
{
echo "\t<table class=\"table\">\n";
echo "\t\t<tr><th>Nazwa</th><th>Godz</th><th>Ilość</th></tr>\n";
while($row_tow = $results_tow->fetch_assoc())
{
//print_r($row_tow);
/*
[id] => 4
[id_firmy] =>
[lic] => BRAK
[data] => 15.10.09
[godz] => 11:10:15
[jedn_miary] => POR.
[status_zam] => 0
[nrdania] => 0
[data_realizacji] =>
[godz_realizacji] =>
[nrsali] => 0
[nrstolika] => 0
[nroperatora] => 1
[uwagi] =>
[czas_przygotowania] => 0
[masa_wprowadzona_przez_kucharza] => 0
[nrmag] => 3
[Identyfikar] => 290
[flagi_towaru] => 3
[drukarki_kuchenne] => 3
[Ident_dok] => 22
[nrtowaru] => 5
[dodatek] => 0
[minutnik] => 0
[status_w_zamowieniu] => 9
[status_zamowienia] => 5
[wydane] => 0
*/
//zmiana statusu zamowienia na nowe, jesli zostanie dodany nowy produkt
if($row_tow['wydane']==0){
$task="UPDATE zamowienia SET status_zam=0, data_aktualizacji=NOW() WHERE id_firmy='".$_SESSION["id_firmy"]."' AND nrzamowienia='".$row_tow['nrzamowienia']."'";
$mysqli->query($task);
}
$dataakt = $row_tow['data']." ".$row_tow['godz'];
$czasakt = strtotime($dataakt);
$datateraz = $row_tow['datateraz'];
$czasteraz = strtotime($datateraz);
//echo $czasakt." teraz: ";
//echo $czasteraz;
//echo "wynik: ".($czasteraz - $czasakt);
echo ( (($czasteraz - $czasakt) >= 1200)&&($row_tow['wydane'] == 0) ? "\t\t<tr class=\"blink\">\n" : "\t\t<tr>\n" );
//echo "\t\t\t<td>".$row_tow['symbol_towaru']."</td>\n";
echo "\t\t\t<td>".
($row_tow['dodatek'] == 0 ? ($row_tow['wydane'] == 1 ? ($row_tow['odebrane'] == 1 ? "<b><del style='color: orange'>".$row_tow['nazwa_towaru']."</del></b>" : "<b><span style='color: green'>".$row_tow['nazwa_towaru']."</span></b>" ) : "<b style='color: black;'>".$row_tow['nazwa_towaru']."</b>") : ($row_tow['wydane'] == 1 ? ($row_tow['odebrane'] == 1 ? "<del style='color: orange'>".$row_tow['nazwa_towaru']."</del>" : "<span style='color:green'>".$row_tow['nazwa_towaru']."</span>" ) : $row_tow['nazwa_towaru']));
if(strlen($row_tow['uwagi'])>0) echo "<br /><i>".$row_tow['uwagi']."</i>";
echo "</td>\n";
echo "<td>".$row_tow['godz']."</td>";
echo "\t\t\t<td>".number_format($row_tow['ilosc_zlecona_kuchni']*0.001, 2 , ",", " ")."</td>\n";
echo "\t\t</tr>\n";
//echo "<li>". ."</li>\n";
}
echo "\t</table>\n";
}
else echo "Brak pozycji towarowych".$mysqli->error;

How to limit inserting data into MySql using codeiginter

How to limit inserting data into MySql using codeiginter?
I have 10000 array data.
But I want to limit only 200 data at each process.
Next process have to insert from data that is not yet inserted.
Here is my code from controller:
<?php
foreach($data["result"] as $key) {
$insert=$this->db->insert('master_mahasiswa_pt',$key );
if (!$insert && $this->db->error()) {
echo "Data nim"; echo " "; echo $key['nipd'] ; echo " "; echo "Sudah Ada"; echo '<br>';
} else {
echo "Data nim"; echo " "; echo $key['nipd'] ; echo " "; echo "Sudah Masuk"; echo '<br>';
}
}
}
}
?>
Here is example from my array data:
Array
(
[error_code] => 0
[error_desc] =>
[result] => Array
(
[0] => Array
(
[id_reg_pd] => 35e86b4f-1b8b-407b-b49e-9d125cba2cb5
[nipd] => 150015020
[id_pd] => b5261e3d-6aed-41e9-a329-1ebe6191d53c
[nm_pd] => ACDB
[tgl_lahir] => 1996-06-16
[id_sms] => 63d9ecdb-4468-4883-a1aa-13ad3f88fce1
[fk__sms] => Teknik Informatika
[id_sp] => 89a93cb2-f959-45d3-8a75-f349be529b87
[fk__sp] => STMIK
[tgl_masuk_sp] => 2015-08-25
[id_jns_daftar] => 1
[fk__jns_daftar] => Peserta didik baru
[id_jns_keluar] =>
[fk__jns_keluar] =>
[tgl_keluar] =>
[ket] =>
[skhun] =>
[a_pernah_paud] => 0
[a_pernah_tk] => 0
[mulai_smt] => 20151
[sks_diakui] => 0
[jalur_skripsi] =>
[judul_skripsi] =>
[bln_awal_bimbingan] =>
[bln_akhir_bimbingan] =>
[sk_yudisium] =>
[tgl_sk_yudisium] =>
[ipk] =>
[no_seri_ijazah] =>
[sert_prof] =>
[a_pindah_mhs_asing] =>
[nm_pt_asal] =>
[nm_prodi_asal] =>
)
)
)
$i = 0;
foreach ($data["result"] as $key) {
if ($i < 201) {
$insert = $this->db->insert('master_mahasiswa_pt', $key);
if (!$insert && $this->db->error()) {
echo "Data nim";
echo " ";
echo $key['nipd'];
echo " ";
echo "Sudah Ada";
echo '<br>';
} else {
echo "Data nim";
echo " ";
echo $key['nipd'];
echo " ";
echo "Sudah Masuk";
echo '<br>';
}
}
$i++;
}

How to check if multidimensional array contains multidimensional array pattern in PHP

I'm looking for niftier check if multidim. array $a matches pattern (key/value) in multidim. array $b (or in other words, check if $b is a subarray of $a). My recursive traversal code with trace help attached below, ready to paste in an empty script.
This is needed to filter mdim array of products using mdim array of its chosen properties to match.
Any simplification appreciated.
<pre>
<?php
$a = array (
"a" => "1",
"b" => "red",
"c" => array(
"ca" => "ca123",
"cb" => "cb123",
),
"d" => array(
"da" => "da123",
"db" => "db123",
"dc" => array(
"dca" => "dca123",
"dcb" => "dcb123"
),
),
);
$b = array(
"b" => "red",
"c" => array(
"ca" => "ca123",
),
"d" => array(
"dc" => array(
"dca" => "dca123",
),
),
);
function is_subarray(&$needle = array(), &$haystack = array())
{
if (!$needle || !$haystack || !is_array($needle) || !is_array($haystack)) return FALSE;
echo __FUNCTION__ . " ENTRY ****************************************************************<br />";
echo "Needle: " . print_r($needle, TRUE) . "<br />Haystack: " . print_r($haystack, TRUE) . "<br />";
foreach ($needle as $needle_key => $needle_value) {
echo "Analyzing needle pair: " . print_r(array($needle_key => $needle_value), TRUE) . "<br />";
echo "and haystack: " . print_r($haystack, TRUE) . "<br />";// . print_r($needle_value, true) . "<br />";
if (array_key_exists($needle_key, $haystack) && (gettype($needle_value) == gettype($haystack[$needle_key]))) {
// Keys matches and values type matches
echo "Keys matches and values type matches<br />";
if (is_array($needle_value)) {
// Values are arrays - going deeper
echo "Values are arrays - going deeper<br />";
if (!is_subarray($needle_value, $haystack[$needle_key])) return FALSE;
} else if ($needle_value != $haystack[$needle_key]) {
// Values don't match - this is the end
echo "Values don't match - this is the end<br />";
return FALSE;
} else {
// Values do match
echo "Values do match<br />";
//$result = true;
}
} else {
// No key found - this is the end
echo "No key found - this is the end<br />";
return FALSE;
}
}
echo __FUNCTION__ . "**************************************************************** EXIT<br />";
return TRUE;
}
echo "<br />Match: " . ((is_subarray($b, $a)) ? "YES" : "NO");
?>
</pre>

Insert data from array_push to database in codeigniter

Hi i hava data in array like this :
$data = Array
(
[0] => Array
(
[kode_pbt] => PBT3-2012-10-19
[kodebr] => 8992802618731
[harga] => 25905.00
[jml] => 1
[subtotal_harga] => 25905
)
[1] => Array
(
[kode_pbt] => PBT3-2012-10-19
[kodebr] => 8992388112401
[harga] => 1340.00
[jml] => 1
[subtotal_harga] => 1340
)
)
my problem is when i want to insert to database
white this code : $this->db->insert($table, $data)
i got an error:
Message: Array to string conversion
I have changed to $this->db->insert_batch($table, $data), but i got error '500 internal server error'.
Thank for your assist.
This is my full function code in controller :
function save_pbt($kode = -1) {
$pbt_detail = array();
$pbt_data = array(
'kode_pbt' => trim($this->input->post('kode_pbt')),
'unit_pemakai' => trim($this->input->post('unit_pemakai')),
'jml_item' => trim($this->input->post('jml_item')),
'total_harga' => trim($this->input->post('total_harga')),
'tgl_pbt' => date('Y-m-d'),
'status' => 0
);
for ($i = 0; $i <= $this->input->post('max_i'); $i++) {
if ($this->input->post('kodebr' . $i)) {
$detail_pbt = array(
'kode_pbt' => $this->input->post('kode_pbt'),
'kodebr' => $this->input->post('kodebr' . $i),
'harga' => $this->input->post('beli' . $i),
'jml' => $this->input->post('jml' . $i),
'subtotal_harga' => $this->input->post('subtotal' . $i)
);
array_push($pbt_detail, $detail_pbt);
}
}
$this->db->trans_begin();
$this->Pbt_model->insert_pbt($pbt_data);
$this->Pbt_model->insert_detail_pbt($pbt_detail);
if ($this->db->trans_status() == FALSE) {
$this->db->trans_rollback();
echo "TRANSACTION ROLLBACK";
} else {
$pbt_data['detail'] = $pbt_detail;
$url = SERVER_SIKOPIT . 'service/service?process=pbt&api_key=' . API_KEY;
$response = json_encode($this->rest_helper($url, $pbt_data, "POST"));
echo $response;
$response = json_decode($response);
if ($response->status == true) {
$this->db->trans_commit();
echo "TRANSACTION SUCCESS";
redirect(site_url('receivings'));
} else {
$this->db->trans_rollback();
echo "INSERT PBT BARU GAGAL !!";
echo "TRANSACTION ROLLBACK";
}
}
}

Categories