note 127520 added to function.printf

From: Date: Sun, 21 Aug 2022 22:32:19 +0000
Subject: note 127520 added to function.printf
Groups: php.notes 
Request: Send a blank email to php-notes+get-219460@lists.php.net to get a copy of this message
To provide a more user-friendly interface, you can use colors when printing text in the terminal. p('Ordinary text.'); p('Warning: Check this out...', 'info'); p('Ops! Something went wrong.', 'error'); p('Yeah... done!', 'success'); function p($text, $style = '', $newLine = true) { $styles = array( 'success' => "\033[0;32m%s\033[0m", 'error' => "\033[31;31m%s\033[0m", 'info' => "\033[33;33m%s\033[0m", 'Black' => "\033[0;30m%s\033[0m", 'Red' => "\033[0;31m%s\033[0m", 'Green' => "\033[0;32m%s\033[0m", 'Yellow' => "\033[0;33m%s\033[0m", 'Blue' => "\033[0;34m%s\033[0m", 'Purple' => "\033[0;35m%s\033[0m", 'Cyan' => "\033[0;36m%s\033[0m", 'Gray' => "\033[0;37m%s\033[0m", 'Graphite' => "\033[1;30m%s\033[0m", 'Bold Red' => "\033[1;31m%s\033[0m", 'Bold Green' => "\033[1;32m%s\033[0m", 'Bold Yellow' => "\033[1;33m%s\033[0m", 'Bold Blue' => "\033[1;34m%s\033[0m", 'Bold Purple' => "\033[1;35m%s\033[0m", 'Bold Cyan' => "\033[1;36m%s\033[0m", 'Bold White' => "\033[1;37m%s\033[0m", 'Bg Black' => "\033[40;1;37m%s\033[0m", 'Bg Red' => "\033[41;1;37m%s\033[0m", 'Bg Green' => "\033[42;1;37m%s\033[0m", 'Bg Yellow' => "\033[43;1;37m%s\033[0m", 'Bg Blue' => "\033[44;1;37m%s\033[0m", 'Bg Purple' => "\033[45;1;37m%s\033[0m", 'Bg Cyan' => "\033[46;1;37m%s\033[0m", 'Bg Gray' => "\033[47;1;37m%s\033[0m", 'Underscore' => "\033[4;37m%s\033[0m", 'Inverted' => "\033[7;37m%s\033[0m", 'Blink' => "\033[5;37m%s\033[0m", ); $format = '%s'; if (isset($styles[$style])) { $format = $styles[$style]; } if ($newLine) { $format .= PHP_EOL; } printf($format, $text); } ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.175 (proxied: 187.36.139.28) ---- Manual Page -- https://php.net/manual/en/function.printf.php Edit -- https://main.php.net/note/edit/127520 Del: integrated -- https://main.php.net/note/delete/127520/integrated Del: useless -- https://main.php.net/note/delete/127520/useless Del: bad code -- https://main.php.net/note/delete/127520/bad+code Del: spam -- https://main.php.net/note/delete/127520/spam Del: non-english -- https://main.php.net/note/delete/127520/non-english Del: in docs -- https://main.php.net/note/delete/127520/in+docs Del: other reasons-- https://main.php.net/note/delete/127520 Reject -- https://main.php.net/note/reject/127520 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#219460) next »