DefaultKeyValue KEY: Value KEY2: Value2 --MULTILINE-KEY-- Multiline value. Which would output something similar to: array( 'ID' => 'DefaultKeyValue', 'KEY' => 'Value', 'KEY2' => 'Value2', 'MULTILINE-KEY' => "Multiline\nvalue.\n", ) We use this as an easy to use file-format for configuration schema files, but the class itself is usage agnostic. You can use ---- to forcibly terminate parsing of a single string-hash; this marker is used in multi string-hashes to delimit boundaries.
示例#1
0
 public function testHtmlt()
 {
     $parser = new HTMLPurifier_StringHashParser();
     $hash = $parser->parseFile($this->path);
     // assume parser normalizes to "\n"
     if (isset($hash['SKIPIF'])) {
         if (eval($hash['SKIPIF'])) {
             return;
         }
     }
     $this->config->set('Output.Newline', "\n");
     if (isset($hash['INI'])) {
         // there should be a more efficient way than writing another
         // ini file every time... probably means building a parser for
         // ini (check out the yaml implementation we saw somewhere else)
         $ini_file = $this->path . '.ini';
         file_put_contents($ini_file, $hash['INI']);
         $this->config->loadIni($ini_file);
     }
     $expect = isset($hash['EXPECT']) ? $hash['EXPECT'] : $hash['HTML'];
     $this->assertPurification(rtrim($hash['HTML']), rtrim($expect));
     if (isset($hash['INI'])) {
         unlink($ini_file);
     }
 }
 public static function buildFromDirectory($dir = null)
 {
     $parser = new HTMLPurifier_StringHashParser();
     $builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
     $interchange = new HTMLPurifier_ConfigSchema_Interchange();
     if (!$dir) {
         $dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema/';
     }
     $info = parse_ini_file($dir . 'info.ini');
     $interchange->name = $info['name'];
     $files = array();
     $dh = opendir($dir);
     while (false !== ($file = readdir($dh))) {
         if (!$file || $file[0] == '.' || strrchr($file, '.') !== '.txt') {
             continue;
         }
         $files[] = $file;
     }
     closedir($dh);
     sort($files);
     foreach ($files as $file) {
         $builder->build($interchange, new HTMLPurifier_StringHash($parser->parseFile($dir . $file)));
     }
     return $interchange;
 }
 public function buildFile($interchange, $file)
 {
     $parser = new HTMLPurifier_StringHashParser();
     $this->build($interchange, new HTMLPurifier_StringHash($parser->parseFile($file)));
 }