You know the PHP flags like ENT_QUOTES when you use htmlentities for example ?
Well you can create your own flags easily.
Here is the code :
PHP Code:
//Lets say we make a function that will transform a string, and we need a flag to choose which transformation
$f = 1;//increment of the flags.
$flags = Array("BOLD","ITALIC","UNDERLINE","BLINK","UPPERCASE");//the flags.
//Now we are gonna MAKE the flags.
foreach($flags as $value) {
define($value,$f);
$f*=2;
}
/*
there are now 5 defines :
BOLD = 1
ITALIC = 2
UNDERLINE = 4
BLINK = 8
UPPERCASE = 16
Now we make the function that will use the flags.
*/
function transform($text,$flags = 0) {
//check the flags, always start with the last flag.
if($flags >= UPPERCASE) {
$text = strtoupper($text);
$flags -= UPPERCASE;
}
if($flags >= BLINK) {
$text = "<blink>".$text."</blink>";
$flags -= BLINK;
}
if($flags >= UNDERLINE) {
$text = "<u>".$text."</u>";
$flags -= UNDERLINE;
}
if($flags >= ITALIC) {
$text = "<i>".$text."</i>";
$flags -= ITALIC;
}
if($flags >= BOLD) {
$text = "<b>".$text."</b>";
$flags -= BOLD;
}
//now return the value
return $text;
}
//Ok if we want to use the function now just pass the string as first param and all the flags you want to use as the second param, using | as separator.
//for example :
echo transform("I am gonna be in bold and uppercase",BOLD|UPPERCASE);