Last active
April 28, 2017 12:17
-
-
Save surferxo3/572510ba1fd3e4c1c3738cba28784bd6 to your computer and use it in GitHub Desktop.
Runtime message output for error logging and monitoring with support for different OS platforms.
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
<?php | |
/*############################# | |
* Developer: Mohammad Sharaf Ali | |
* Designation: Web Developer | |
* Version: 1.0 | |
*/############################# | |
// HELPER METHODS | |
function br2nl($str) { | |
return preg_replace('#<br\s*?/?>#i', PHP_EOL, $str); | |
} | |
function toScreen($data, $exit = false) { | |
$isCli = !empty($_REQUEST['curl']) || substr(PHP_SAPI, 0, 3) === 'cli' ? true : false; | |
ob_implicit_flush(true); | |
// if html is there in $data then use array_map('htmlentities', $data) | |
if (is_object($data) || is_array($data)) { | |
echo ($isCli ? print_r($data, true) : '<pre>' . print_r($data, true) . '</pre>') ; | |
} else { | |
echo ($isCli ? br2nl($data) . PHP_EOL : nl2br($data, true) . '<br />' ); | |
} | |
ob_get_level() > 0 ? ob_flush() : flush(); | |
ob_implicit_flush(false); | |
if ($exit) { | |
exit; | |
} | |
} | |
// MAIN | |
for ($i = 1; $i <= 10; $i++) { | |
toScreen('10 x ' . $i . ' = ' . (10 * $i) . '<br />'); | |
sleep(2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment