function encode($decoded, $one_time_encoding = false)
    {
        // Forcing conversion of input to UCS4 array
        // If one time encoding is given, use this, else the objects property
        switch ($one_time_encoding ? $one_time_encoding : $this->_api_encoding) {
        case 'utf8':
            $decoded = $this->_utf8_to_ucs4($decoded);
            break;
        case 'ucs4_string':
           $decoded = $this->_ucs4_string_to_ucs4($decoded);
        case 'ucs4_array':
           break;
        default:
            $this->_error('Unsupported input format: '.($one_time_encoding ? $one_time_encoding : $this->_api_encoding));
            return false;
        }

        // No input, no output, what else did you expect?
        if (empty($decoded)) return '';

        // Anchors for iteration
        $last_begin = 0;
        // Output string
        $output = '';
        foreach ($decoded as $k => $v) {
            // Make sure to use just the plain dot
            switch($v) {
            case 0x3002:
            case 0xFF0E:
            case 0xFF61:
                $decoded[$k] = 0x2E;
                // Right, no break here, the above are converted to dots anyway
            // Stumbling across an anchoring character
            case 0x2E:
            case 0x2F:
            case 0x3A:
            case 0x3F:
            case 0x40:
                // Neither email addresses nor URLs allowed in strict mode
                if ($this->_strict_mode) {
                   $this->_error('Neither email addresses nor URLs are allowed in strict mode.');
                   return false;
                }

                // Skip first char
                if ($k) {
                    $encoded = '';
                    $encoded = $this->_encode(array_slice($decoded, $last_begin, (($k)-$last_begin)));
                    if ($encoded) {
                        $output .= $encoded;
                    } else {
                        $output .= $this->_ucs4_to_utf8(array_slice($decoded, $last_begin, (($k)-$last_begin)));
                    }
                    $output .= chr($decoded[$k]);
                }
                $last_begin = $k + 1;
            }
        }
        // Catch the rest of the string
        if ($last_begin) {
            $inp_len = sizeof($decoded);
            $encoded = '';
            $encoded = $this->_encode(array_slice($decoded, $last_begin, (($inp_len)-$last_begin)));
            if ($encoded) {
                $output .= $encoded;
            } else {
                $output .= $this->_ucs4_to_utf8(array_slice($decoded, $last_begin, (($inp_len)-$last_begin)));
            }
            return $output;
        }

        if ($output = $this->_encode($decoded)) {
            return $output;
        }

        return $this->_ucs4_to_utf8($decoded);
    }
function encode($decoded, $one_time_encoding = false)
    {
        // Forcing conversion of input to UCS4 array
        // If one time encoding is given, use this, else the objects property
        switch ($one_time_encoding ? $one_time_encoding : $this->_api_encoding) {
        case 'utf8':
            $decoded = $this->_utf8_to_ucs4($decoded);
            break;
        case 'ucs4_string':
           $decoded = $this->_ucs4_string_to_ucs4($decoded);
        case 'ucs4_array':
           break;
        default:
            $this->_error('Unsupported input format: '.($one_time_encoding ? $one_time_encoding : $this->_api_encoding));
            return false;
        }

        // No input, no output, what else did you expect?
        if (empty($decoded)) return '';

        // Anchors for iteration
        $last_begin = 0;
        // Output string
        $output = '';
        foreach ($decoded as $k => $v) {
            // Make sure to use just the plain dot
            switch($v) {
            case 0x3002:
            case 0xFF0E:
            case 0xFF61:
                $decoded[$k] = 0x2E;
                // Right, no break here, the above are converted to dots anyway
            // Stumbling across an anchoring character
            case 0x2E:
            case 0x2F:
            case 0x3A:
            case 0x3F:
            case 0x40:
                // Neither email addresses nor URLs allowed in strict mode
                if ($this->_strict_mode) {
                   $this->_error('Neither email addresses nor URLs are allowed in strict mode.');
                   return false;
                }

                // Skip first char
                if ($k) {
                    $encoded = '';
                    $encoded = $this->_encode(array_slice($decoded, $last_begin, (($k)-$last_begin)));
                    if ($encoded) {
                        $output .= $encoded;
                    } else {
                        $output .= $this->_ucs4_to_utf8(array_slice($decoded, $last_begin, (($k)-$last_begin)));
                    }
                    $output .= chr($decoded[$k]);
                }
                $last_begin = $k + 1;
            }
        }
        // Catch the rest of the string
        if ($last_begin) {
            $inp_len = sizeof($decoded);
            $encoded = '';
            $encoded = $this->_encode(array_slice($decoded, $last_begin, (($inp_len)-$last_begin)));
            if ($encoded) {
                $output .= $encoded;
            } else {
                $output .= $this->_ucs4_to_utf8(array_slice($decoded, $last_begin, (($inp_len)-$last_begin)));
            }
            return $output;
        }

        if ($output = $this->_encode($decoded)) {
            return $output;
        }

        return $this->_ucs4_to_utf8($decoded);
    }
function encode ( $ decoded , $ one_time_encoding = false ) { // Forcing conversion of input to UCS4 array // If one time encoding is given, use this, else the objects property switch ( $ one_time_encoding ? $ one_time_encoding : $ this -> _api_encoding ) { case 'utf8' : $ decoded = $ this -> _utf8_to_ucs4 ( $ decoded ) ; break ; case 'ucs4_string' : $ decoded = $ this -> _ucs4_string_to_ucs4 ( $ decoded ) ; case 'ucs4_array' : break ; default : $ this -> _error ( 'Unsupported input format: ' . ( $ one_time_encoding ? $ one_time_encoding : $ this -> _api_encoding ) ) ; return false ; } // No input, no output, what else did you expect? if ( empty ( $ decoded ) ) return '' ; // Anchors for iteration $ last_begin = 0 ; // Output string $ output = '' ; foreach ( $ decoded as $ k => $ v ) { // Make sure to use just the plain dot switch ( $ v ) { case 0x3002 : case 0xFF0E : case 0xFF61 : $ decoded [ $ k ] = 0x2E ; // Right, no break here, the above are converted to dots anyway // Stumbling across an anchoring character case 0x2E : case 0x2F : case 0x3A : case 0x3F : case 0x40 : // Neither email addresses nor URLs allowed in strict mode if ( $ this -> _strict_mode ) { $ this -> _error ( 'Neither email addresses nor URLs are allowed in strict mode.' ) ; return false ; } // Skip first char if ( $ k ) { $ encoded = '' ; $ encoded = $ this -> _encode ( array_slice ( $ decoded , $ last_begin , ( ( $ k ) - $ last_begin ) ) ) ; if ( $ encoded ) { $ output .= $ encoded ; } else { $ output .= $ this -> _ucs4_to_utf8 ( array_slice ( $ decoded , $ last_begin , ( ( $ k ) - $ last_begin ) ) ) ; } $ output .= chr ( $ decoded [ $ k ] ) ; } $ last_begin = $ k + 1 ; } } // Catch the rest of the string if ( $ last_begin ) { $ inp_len = sizeof ( $ decoded ) ; $ encoded = '' ; $ encoded = $ this -> _encode ( array_slice ( $ decoded , $ last_begin , ( ( $ inp_len ) - $ last_begin ) ) ) ; if ( $ encoded ) { $ output .= $ encoded ; } else { $ output .= $ this -> _ucs4_to_utf8 ( array_slice ( $ decoded , $ last_begin , ( ( $ inp_len ) - $ last_begin ) ) ) ; } return $ output ; } if ( $ output = $ this -> _encode ( $ decoded ) ) { return $ output ; } return $ this -> _ucs4_to_utf8 ( $ decoded ) ; }
Encode a given UTF-8 domain name
@param    string   Domain name (UTF-8 or UCS-4)
[@param    string   Desired input encoding, see {@link set_parameter}]
@return   string   Encoded Domain name (ACE string)
@access   public
Encode a given UTF - 8 domain name