note 128752 added to function.print-r

From: Date: Fri, 21 Jul 2023 21:44:13 +0000
Subject: note 128752 added to function.print-r
Groups: php.notes 
Request: Send a blank email to php-notes+get-220712@lists.php.net to get a copy of this message
<?php /** collapse all the space-wasting single-line-parenthesis */ function debug(mixed $value): string { return preg_replace( '/\s+([\(\)])$/m', '$1', print_r($value, true)); } /* this changes: Array ( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ) ) to: Array( [a] => apple [b] => banana [c] => Array( [0] => x [1] => y [2] => z)) Note: if you are dealing with lots of data that have new lines and parenthesis, you might want a more expensive regex that takes line breaks into account... but this should only remove whitespace anyway. */ ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.159.168 (proxied: 186.203.158.67) ---- Manual Page -- https://php.net/manual/en/function.print-r.php Edit -- https://main.php.net/note/edit/128752 Del: integrated -- https://main.php.net/note/delete/128752/integrated Del: useless -- https://main.php.net/note/delete/128752/useless Del: bad code -- https://main.php.net/note/delete/128752/bad+code Del: spam -- https://main.php.net/note/delete/128752/spam Del: non-english -- https://main.php.net/note/delete/128752/non-english Del: in docs -- https://main.php.net/note/delete/128752/in+docs Del: other reasons-- https://main.php.net/note/delete/128752 Reject -- https://main.php.net/note/reject/128752 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220712) next »