HTMLPurifier_Lexer::parseData PHP Method

parseData() public method

This string will translate escaped versions of the special characters into the correct ones.
public parseData ( string $string ) : string
$string string String character data to be parsed.
return string Parsed character data.
    public function parseData($string)
    {
        // following functions require at least one character
        if ($string === '') {
            return '';
        }
        // subtracts amps that cannot possibly be escaped
        $num_amp = substr_count($string, '&') - substr_count($string, '& ') - ($string[strlen($string) - 1] === '&' ? 1 : 0);
        if (!$num_amp) {
            return $string;
        }
        // abort if no entities
        $num_esc_amp = substr_count($string, '&');
        $string = strtr($string, $this->_special_entity2str);
        // code duplication for sake of optimization, see above
        $num_amp_2 = substr_count($string, '&') - substr_count($string, '& ') - ($string[strlen($string) - 1] === '&' ? 1 : 0);
        if ($num_amp_2 <= $num_esc_amp) {
            return $string;
        }
        // hmm... now we have some uncommon entities. Use the callback.
        $string = $this->_entity_parser->substituteSpecialEntities($string);
        return $string;
    }

Usage Example

Beispiel #1
0
 function assertParseData($input, $expect = true)
 {
     if ($expect === true) {
         $expect = $input;
     }
     $lexer = new HTMLPurifier_Lexer();
     $this->assertIdentical($expect, $lexer->parseData($input));
 }