Functions
WebDev/*nix assorted functions & hacks
Search
find all
Array
-
Bash
-
Classes
-
Config
-
DateTime
-
Debug
-
dotjs
-
File
-
foooo
-
Git
-
HTML
-
Images
-
Javascript
-
Linux
-
Math
-
Misc
-
MySQL
-
OS X
-
Reading
-
Redis
-
Shell scripts
-
snippets
-
SQL
-
Strings
-
TextMate
-
Web
-
\(^o^)/ Fun!
-
_Misc hacks
-
_Pages
HTML
* Readme
pageStart($list)
popup_link(...)
styled($string, $color='black', $style='')
template($file, $assoc_data)
5
found
auth
Name:
Category: HTML
Body:
function styled($str, $color='red', $style='') { if (PHP_SAPI === 'cli') { // 'cli-server' for PHP's own server. return styledCLI($str, $color, $style); } return styledHTML($str, $color, $style); } function styledCLI($str, $color='red', $style='') { $colors = array( 'red' => '31', 'green' => '32', 'yellow' => '33', 'blue' => '34', 'magenta' => '35', 'cyan' => '36', 'white' => '37', 'black' => '30', ); $styles = array( 'bold' => 1, 'strong' => 1, 'underline' => 2, 'background' => 3, 'inverse' => 3, 'blink' => 5, ); $codes[] = isset($colors[$color]) ? $colors[$color] : '0'; foreach(preg_split('/\s+/', $style) as $style) if (isset($styles[$style])) $codes[] = $styles[$style]; return "\033[".join(';',$codes)."m$str\033[0m"; } function styledHTML($string, $color = 'black', $style = '') { if (func_num_args() == 1) return $string; $style_str = "color: $color; "; $style = strtolower($style); $styles = [ 'bold' => 'font-weight: bold;', 'italic' => 'font-style: italic;', 'underline' => 'text-decoration: underline;', 'pre' => 'white-space: pre;', ]; foreach(preg_split('/\s+/', $style) as $key => $declaration) if (isset($styles[$style])) $style_str .= ' '.$styles[$style]; $string = "<span style='$style_str'>$string</span>"; return $string; }
Footer