Results 1 to 3 of 3

Thread: [PHP] Quick way to create your own Flags

  1. #1
    nirahiel is offline Junior Member
    Join Date
    Jul 2009
    Posts
    3

    Default [PHP] Quick way to create your own Flags

    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); 

  2. #2
    itsgreg_x's Avatar
    itsgreg_x is offline Member
    Join Date
    Jul 2009
    Location
    Slovenia (;
    Age
    18
    Posts
    54

    Default

    Maybe you should make a tutorial for it.
    Like explaining syntax and stuff?
    I called Sasuke gay, and he hit me with his purse ;(



  3. #3
    jesu is offline Member
    Join Date
    Jul 2009
    Posts
    58

    Default

    make a description of every lines... ahahah.. is it hard?
    I am what i am.. - jesu11

    jesu11 from GamerzNeeds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •