<?php function parsePrintR(string $printRString): array { $printRString = trim($printRString); // Remove o texto inicial 'Array' e o parêntese de abertura if (stripos($printRString, 'Array') === 0) { $printRString = substr($printRString, strpos($printRString, '(') + 1); // Remove o último parêntese de fechamento correspondente $printRString = substr($printRString, 0, strrpos($printRString, ')')); } $result = []; $len = strlen($printRString); $i = 0; while ($i < $len) { // Ignora espaços e quebras de linha while ($i < $len && (ctype_space($printRString[$i]) || $printRString[$i] === "\n")) { $i++; } if ($i >= $len) break; // Busca chave entre colchetes if ($printRString[$i] === '[') { $i++; $key = ''; while ($i < $len && $printRString[$i] !== ']') { $key .= $printRString[$i++]; } $i++; // pula o ']' // pula espaços while ($i < $len && ctype_space($printRString[$i])) $i++; // espera '=>' if (substr($printRString, $i, 2) === '=>') { $i += 2; while ($i < $len && ctype_space($printRString[$i])) $i++; // Verifica se é um array if (stripos(substr($printRString, $i, 5), 'Array') === 0) { $i += 5; while ($i < $len && ctype_space($printRString[$i])) $i++; if ($printRString[$i] === '(') { $i++; $start = $i; $depth = 1; while ($i < $len && $depth > 0) { if ($printRString[$i] === '(') $depth++; if ($printRString[$i] === ')') $depth--; $i++; } $subArrayStr = substr($printRString, $start, $i - $start - 1); $result[$key] = parsePrintR('Array(' . $subArrayStr . ')'); } } else { // Valor simples $value = ''; // Lê até o fim da linha ou até encontrar um novo [key] while ($i < $len && $printRString[$i] !== "\n") { $value .= $printRString[$i++]; } $result[$key] = trim($value); } } } else { // ignora linhas que não começam com chave while ($i < $len && $printRString[$i] !== "\n") $i++; $i++; } } return $result; } $input = "Erro ao enviar o ipn: \nParams: Array\n(\n [0] => Array\n (\n [order] => abcde\n [payment_method] => C\n [payment_status] => A\n [xppmaster] => 123\n [hmac] => qwee123\n [payment_email] => 0\n [amount_paid] => 152.34\n [authorization_code] => 1234\n [apply_discount_into_checkout] => 0\n [only_update_order] => 1\n [cc_auth] => 2\n )\n\n [1] => Array\n (\n [id] => 213215421521\n [por_hora] => 2025-08-25 22:42:28\n [x_reference] => abcde\n [merchants_id] => 571\n [checkout_id] => 312341214\n [payment_method] => C\n [payment_status] => W\n [authorization_code] => 1234\n [utf8] => \n [authenticity_token] => \n [x_account_id] => avwdegfeeg\n [x_amount] => 152.34\n [x_pag_fee_applied] => 0\n [x_currency] => BRL\n [x_discount_type] => \n [x_discount] => \n [x_subtotal_discount] => \n [x_url_callback] => url.site.com\n [x_url_complete] => url.site.com\n [x_checkout_token] => aveofwjifw\n [x_order_id_shopify] => 1234\n [x_is_recurring] => 0\n [x_original_order] => \n [x_recurring_created_at] => \n [x_recurring_integrated_at] => \n [x_shop_country] => BR\n [x_shop_name] => \n [x_transaction_type] => \n [x_test] => false\n [x_customer_first_name] => João\n [x_customer_last_name] => doe\n [x_customer_email] => mail@mail.com\n [x_customer_phone] => 123421325421\n [x_customer_billing_country] => BR\n [x_customer_billing_first_name] => João\n [x_customer_billing_last_name] => doe\n [x_customer_billing_city] => Belo Horizonte\n [x_customer_billing_company] => 02991215690\n [x_customer_billing_address1] => Av. dadwwd, WJ1964\n [x_customer_billing_address2] => 7° andar, WJFuncionários\n [x_customer_billing_state] => Minas Gerais\n [x_customer_billing_zip] => 11111-3333\n [x_customer_billing_phone] => 123421325421\n [x_customer_shipping_country] => BR\n [x_customer_shipping_first_name] => João\n [x_customer_shipping_last_name] => doe\n [x_customer_shipping_city] => Belo Horizonte\n [x_customer_shipping_company] => 32321442141\n [x_customer_shipping_address1] => Av. dadwwd, WJ1964\n [x_customer_shipping_address2] => 7° andar, WJFuncionários\n [x_customer_shipping_state] => Minas Gerais\n [x_customer_shipping_zip] => 123213123-33333\n [x_customer_shipping_phone] => 123421325421\n [x_invoice] => \n [x_amount_shipping] => \n [x_amount_tax] => \n [x_description] => Products\n [x_url_cancel] => \n [x_signature] => \n [x_timestamp] => \n [x_fallback_payment] => \n [locale] => \n [commit] => \n [info_discounts_applied_into_checkout] => \n [pix_expiration_date] => \n [pix_expiration_time] => \n [pix_code] => \n [pix_image] => \n [boleto_url] => \n [boleto_expiration_date] => \n [nsu] => 1234\n [tid] => 8adwadwawafwafwaf\n [processed_by_google_pay] => 0\n [note_attribute_updated] => 0\n [processed_by_apple_pay] => 0\n [conciliate_at] => \n [payment_status_verified_at] => \n [pix_rec_id] => \n [x_merchantid] => 123\n [pix_order_pending] => 0\n [pix_thank_you_page] => 0\n )\n\n [2] => Array\n (\n [x_account_id] => avwdegfeeg\n [x_amount] => 152.34\n [x_currency] => BRL\n [x_gateway_reference] => ba123452025-08-26T01:46:08Z157230\n [x_message] => Payment Method: Cartão de crédito\n [x_reference] => abcde\n [x_result] => completed\n [x_test] => false\n [x_timestamp] => 2025-08-26T01:46:08Z\n [x_signature] => abvfefsfesf\n )\n\n)\n\nError: Error in sendIpnToShopify: Error in resolvePaymentStatusToPending: Error ao fazer a mutation de paymentSessionPending: \nArray\n(\n [0] => Array\n (\n [field] => Array\n (\n [0] => id\n )\n\n [message] => Payment session has already been resolved\/rejected, has already been pended with a different reason, or the response to start_payment_session request has not been received.\n )\n\n)\n"; $string = $input; // 1. Isolar os blocos de "Array(...)" da sua string de log preg_match_all('/Array\s*\((.|\n)*?\)\s*\n/s', $string, $arrayBlocks); //print_r($arrayBlocks); $jsonResults = []; foreach ($arrayBlocks[0] as $i => $block) { // echo "Começando index $i " . PHP_EOL; // echo PHP_EOL; // print_r($block); // echo PHP_EOL; // 2. Para cada bloco encontrado, converte para array $phpArray = parsePrintR($block); // 3. Adiciona ao resultado $jsonResults[] = $phpArray; } // 4. Converte o resultado final para JSON formatado $finalJson = json_encode($jsonResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); print_r($finalJson);
You have javascript disabled. You will not be able to edit any code.