HTMLPurifier_PercentEncoder::encode PHP Method

encode() public method

Our replacement for urlencode, it encodes all non-reserved characters, as well as any extra characters that were instructed to be preserved.
public encode ( string $string ) : string
$string string String to be encoded
return string Encoded string.
    public function encode($string)
    {
        $ret = '';
        for ($i = 0, $c = strlen($string); $i < $c; $i++) {
            if ($string[$i] !== '%' && !isset($this->preserve[$int = ord($string[$i])])) {
                $ret .= '%' . sprintf('%02X', $int);
            } else {
                $ret .= $string[$i];
            }
        }
        return $ret;
    }

Usage Example

Esempio n. 1
0
 public function assertEncode($string, $expect = true, $preserve = false)
 {
     if ($expect === true) {
         $expect = $string;
     }
     $encoder = new HTMLPurifier_PercentEncoder($preserve);
     $result = $encoder->encode($string);
     $this->assertIdentical($result, $expect);
 }
All Usage Examples Of HTMLPurifier_PercentEncoder::encode
HTMLPurifier_PercentEncoder