本文整理汇总了PHP中Sanitizer::hackDocType方法的典型用法代码示例。如果您正苦于以下问题:PHP Sanitizer::hackDocType方法的具体用法?PHP Sanitizer::hackDocType怎么用?PHP Sanitizer::hackDocType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sanitizer
的用法示例。
在下文中一共展示了Sanitizer::hackDocType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isWellFormedXmlFragment
/**
* Check if a string is a well-formed XML fragment.
* Wraps fragment in an \<html\> bit and doctype, so it can be a fragment
* and can use HTML named entities.
*
* @param string $text
* @return bool
*/
public static function isWellFormedXmlFragment($text)
{
$html = Sanitizer::hackDocType() . '<html>' . $text . '</html>';
return Xml::isWellFormed($html);
}
示例2: wfIsWellFormedXmlFragment
/**
* Check if a string is a well-formed XML fragment.
* Wraps fragment in an <html> bit and doctype, so it can be a fragment
* and can use HTML named entities.
*
* @param string $text
* @return bool
*/
function wfIsWellFormedXmlFragment($text)
{
$html = Sanitizer::hackDocType() . '<html>' . $text . '</html>';
return wfIsWellFormedXml($html);
}
示例3: htmlDiff
function htmlDiff($from, $to)
{
// Create an XML parser
$xml_parser = xml_parser_create('');
$domfrom = new DomTreeBuilder();
// Set the functions to handle opening and closing tags
xml_set_element_handler($xml_parser, array($domfrom, "startElement"), array($domfrom, "endElement"));
// Set the function to handle blocks of character data
xml_set_character_data_handler($xml_parser, array($domfrom, "characters"));
HTMLDiffer::diffDebug("Parsing " . strlen($from) . " characters worth of HTML\n");
if (!xml_parse($xml_parser, '<?xml version="1.0" encoding="UTF-8"?>' . Sanitizer::hackDocType() . '<body>', false) || !xml_parse($xml_parser, $from, false) || !xml_parse($xml_parser, '</body>', true)) {
$error = xml_error_string(xml_get_error_code($xml_parser));
$line = xml_get_current_line_number($xml_parser);
$col = xml_get_current_column_number($xml_parser);
HTMLDiffer::diffDebug("XML error: {$error} at line {$line} and column {$col}\n");
}
xml_parser_free($xml_parser);
unset($from);
$xml_parser = xml_parser_create('');
$domto = new DomTreeBuilder();
// Set the functions to handle opening and closing tags
xml_set_element_handler($xml_parser, array($domto, "startElement"), array($domto, "endElement"));
// Set the function to handle blocks of character data
xml_set_character_data_handler($xml_parser, array($domto, "characters"));
HTMLDiffer::diffDebug("Parsing " . strlen($to) . " characters worth of HTML\n");
if (!xml_parse($xml_parser, '<?xml version="1.0" encoding="UTF-8"?>' . Sanitizer::hackDocType() . '<body>', false) || !xml_parse($xml_parser, $to, false) || !xml_parse($xml_parser, '</body>', true)) {
$error = xml_error_string(xml_get_error_code($xml_parser));
$line = xml_get_current_line_number($xml_parser);
$col = xml_get_current_column_number($xml_parser);
HTMLDiffer::diffDebug("XML error: {$error} at line {$line} and column {$col}\n");
}
xml_parser_free($xml_parser);
unset($to);
$diffengine = new WikiDiff3();
$differences = $this->preProcess($diffengine->diff_range($domfrom->getDiffLines(), $domto->getDiffLines()));
unset($xml_parser, $diffengine);
$textNodeDiffer = new TextNodeDiffer($domto, $domfrom);
$currentIndexLeft = 0;
$currentIndexRight = 0;
foreach ($differences as &$d) {
if ($d->leftstart > $currentIndexLeft) {
$textNodeDiffer->handlePossibleChangedPart($currentIndexLeft, $d->leftstart, $currentIndexRight, $d->rightstart);
}
if ($d->leftlength > 0) {
$textNodeDiffer->markAsDeleted($d->leftstart, $d->leftend, $d->rightstart);
}
$textNodeDiffer->markAsNew($d->rightstart, $d->rightend);
$currentIndexLeft = $d->leftend;
$currentIndexRight = $d->rightend;
}
$oldLength = $textNodeDiffer->lengthOld();
if ($currentIndexLeft < $oldLength) {
$textNodeDiffer->handlePossibleChangedPart($currentIndexLeft, $oldLength, $currentIndexRight, $textNodeDiffer->lengthNew());
}
$textNodeDiffer->expandWhiteSpace();
$output = new HTMLOutput('htmldiff');
return $output->parse($textNodeDiffer->bodyNode);
}
示例4: wellFormed
private function wellFormed($text)
{
$html = Sanitizer::hackDocType() . '<html>' . $text . '</html>';
$parser = xml_parser_create("UTF-8");
# case folding violates XML standard, turn it off
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
if (!xml_parse($parser, $html, true)) {
$err = xml_error_string(xml_get_error_code($parser));
$position = xml_get_current_byte_index($parser);
$fragment = $this->extractFragment($html, $position);
$this->xmlError = "{$err} at byte {$position}:\n{$fragment}";
xml_parser_free($parser);
return false;
}
xml_parser_free($parser);
return true;
}