bitfield::set PHP Method

set() public method

public set ( $n )
    function set($n)
    {
        $byte = $n >> 3;
        $bit = 7 - ($n & 7);
        if (strlen($this->data) >= $byte + 1) {
            $this->data[$byte] = $this->data[$byte] | chr(1 << $bit);
        } else {
            $this->data .= str_repeat("", $byte - strlen($this->data));
            $this->data .= chr(1 << $bit);
        }
    }

Usage Example

Example #1
0
 /**
  * Parse BBCode
  */
 function parse_bbcode()
 {
     if (!$this->bbcodes) {
         $this->bbcode_init();
     }
     global $user;
     $this->bbcode_bitfield = '';
     $bitfield = new bitfield();
     foreach ($this->bbcodes as $bbcode_name => $bbcode_data) {
         if (isset($bbcode_data['disabled']) && $bbcode_data['disabled']) {
             foreach ($bbcode_data['regexp'] as $regexp => $replacement) {
                 if (preg_match($regexp, $this->message)) {
                     $this->warn_msg[] = sprintf($user->lang['UNAUTHORISED_BBCODE'], '[' . $bbcode_name . ']');
                     continue;
                 }
             }
         } else {
             foreach ($bbcode_data['regexp'] as $regexp => $replacement) {
                 // The pattern gets compiled and cached by the PCRE extension,
                 // it should not demand recompilation
                 if (preg_match($regexp, $this->message)) {
                     $this->message = preg_replace($regexp, $replacement, $this->message);
                     $bitfield->set($bbcode_data['bbcode_id']);
                 }
             }
         }
     }
     $this->bbcode_bitfield = $bitfield->get_base64();
 }
All Usage Examples Of bitfield::set