Created
February 13, 2019 15:04
-
-
Save wapcrazut/0a87c7dffeab4a9656d6ccf186fc64be to your computer and use it in GitHub Desktop.
Beautify var_dump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Var dumper Formater</title> | |
| <style> | |
| body { | |
| font-family: "Courier New", Courier, monospace; | |
| padding-bottom:50px; | |
| } | |
| textarea { | |
| width:100%; | |
| height:250px; | |
| } | |
| .doIt { | |
| width:100%; | |
| height:35px; | |
| margin-bottom:25px; | |
| } | |
| </style> | |
| <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
| <script> | |
| (function($) { | |
| // Source: http://www.bennadel.com/blog/142-ask-ben-javascript-string-replace-method.htm | |
| // Replaces all instances of the given substring. | |
| String.prototype.replaceAll = function( | |
| strTarget, // The substring you want to replace | |
| strSubString // The string you want to replace in. | |
| ){ | |
| var strText = this; | |
| var intIndexOfMatch = strText.indexOf( strTarget ); | |
| // Keep looping while an instance of the target string | |
| // still exists in the string. | |
| while (intIndexOfMatch != -1){ | |
| // Relace out the current instance. | |
| strText = strText.replace( strTarget, strSubString ) | |
| // Get the index of any next matching substring. | |
| intIndexOfMatch = strText.indexOf( strTarget ); | |
| } | |
| // Return the updated string with ALL the target strings | |
| // replaced out with the new substring. | |
| return( strText ); | |
| } | |
| $('.doIt').click(function(){ | |
| var input = $('textarea').val(); | |
| var output = ''; | |
| var indent = 0; | |
| // let's do some labour! | |
| input = input.replaceAll('{ [', '{<br>['); | |
| input = input.replaceAll('" ["', '"<br>["'); | |
| input = input.replaceAll('NULL [', 'NULL <br>['); | |
| input = input.replaceAll('} ["', '}<br>["'); | |
| input = input.replaceAll('} }', '}<br>}'); | |
| input = input.replaceAll(') [', ')<br>['); | |
| for (var i = 0, len = input.length; i < len; i++) { | |
| output = output + input[i]; | |
| } | |
| $('.output').html(input); | |
| }) | |
| })(jQuery) | |
| </script> | |
| </head> | |
| <body> | |
| Real crappy PHP var_dump beautifier | |
| <!-- will put some linebreaks for non-xdebug var_dumps --> | |
| <!-- based on inferior logic and methods --> | |
| <!-- Todo: indentation (but likely never to happen due to laziness) --> | |
| <textarea placeholder='object(Mage_Sales_Model_Order)#119 (29) { ["_eventPrefix":protected]=> string(11) "sales_order" ["_eventObject":protected]=> string(5) "order" ["_addresses":protected]=> NULL ["_items":protected]=> NULL ["_payments":protected]=> NULL ["_statusHistory":protected]=> NULL ["_invoices":protected]=> NULL ["_tracks":protected]=> NULL ["_shipments":protected]=> NULL ["_creditmemos":protected]=> NULL ["_relatedObjects":protected]=> array(0) { } ["_orderCurrency":protected]=> NULL ["_baseCurrency":protected]=> NULL ["_actionFlag":protected]=> array(0) { } ["_canSendNewEmailFlag":protected]=> bool(true) ["_historyEntityName":protected]=> string(5) "order" ["_resourceName":protected]=> string(11) "sales/order" ["_resource":protected]=> NULL ["_resourceCollectionName":protected]=> string(22) "sales/order_collection" ["_cacheTag":protected]=> bool(false) ["_dataSaveAllowed":protected]=> bool(true) ["_isObjectNew":protected]=> NULL ["_data":protected]=> array(140) { ["entity_id"]=> string(4) "1234" ["state"]=> string(8) "complete" ["status"]=> string(8) "complete" ["coupon_code"]=> NULL ["protect_code"]=> string(6) "e64c0a" ["shipping_description"]=> NULL ["is_virtual"]=> string(1) "1" ["store_id"]=> string(1) "1" ["customer_id"]=> string(4) "9999" ["base_discount_amount"]=> string(6) "0.0000" ["base_discount_canceled"]=> NULL ["base_discount_invoiced"]=> string(6) "0.0000" ["base_discount_refunded"]=> NULL ["base_grand_total"]=> string(9) "999.0000" ["base_shipping_amount"]=> string(6) "0.0000"'></textarea> | |
| <button class="doIt">Do It</button> | |
| <div class="output"> | |
| // SAMPLE OUTPUT<br> | |
| object(Mage_Sales_Model_Order)#119 (29) {<br>["_eventPrefix":protected]=> string(11) "sales_order"<br>["_eventObject":protected]=> string(5) "order"<br>["_addresses":protected]=> NULL <br>["_items":protected]=> NULL <br>["_payments":protected]=> NULL <br>["_statusHistory":protected]=> NULL <br>["_invoices":protected]=> NULL <br>["_tracks":protected]=> NULL <br>["_shipments":protected]=> NULL <br>["_creditmemos":protected]=> NULL <br>["_relatedObjects":protected]=> array(0) { }<br>["_orderCurrency":protected]=> NULL <br>["_baseCurrency":protected]=> NULL <br>["_actionFlag":protected]=> array(0) { }<br>["_canSendNewEmailFlag":protected]=> bool(true)<br>["_historyEntityName":protected]=> string(5) "order"<br>["_resourceName":protected]=> string(11) "sales/order"<br>["_resource":protected]=> NULL <br>["_resourceCollectionName":protected]=> string(22) "sales/order_collection"<br>["_cacheTag":protected]=> bool(false)<br>["_dataSaveAllowed":protected]=> bool(true)<br>["_isObjectNew":protected]=> NULL <br>["_data":protected]=> array(140) {<br>["entity_id"]=> string(4) "1234"<br>["state"]=> string(8) "complete"<br>["status"]=> string(8) "complete"<br>["coupon_code"]=> NULL <br>["protect_code"]=> string(6) "e64c0a"<br>["shipping_description"]=> NULL <br>["is_virtual"]=> string(1) "1"<br>["store_id"]=> string(1) "1"<br>["customer_id"]=> string(4) "9999"<br>["base_discount_amount"]=> string(6) "0.0000"<br>["base_discount_canceled"]=> NULL <br>["base_discount_invoiced"]=> string(6) "0.0000"<br>["base_discount_refunded"]=> NULL <br>["base_grand_total"]=> string(9) "999.0000"<br>["base_shipping_amount"]=> string(6) "0.0000" | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment