本文整理汇总了PHP中tidy_repair_string函数的典型用法代码示例。如果您正苦于以下问题:PHP tidy_repair_string函数的具体用法?PHP tidy_repair_string怎么用?PHP tidy_repair_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tidy_repair_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: repair
/**
* Repair HTML. If Tidy not exists, use repair function.
*
* @param string $html The HTML string to repair.
* @param boolean $use_tidy Force tidy or not.
*
* @return string Repaired HTML.
*/
public static function repair($html, $use_tidy = true)
{
if (function_exists('tidy_repair_string') && $use_tidy) {
$TidyConfig = array('indent' => true, 'output-xhtml' => true, 'show-body-only' => true, 'wrap' => false);
return tidy_repair_string($html, $TidyConfig, 'utf8');
} else {
$arr_single_tags = array('meta', 'img', 'br', 'link', 'area');
// Put all opened tags into an array
preg_match_all("#<([a-z]+)( .*)?(?!/)>#iU", $html, $result);
$openedtags = $result[1];
// Put all closed tags into an array
preg_match_all("#</([a-z]+)>#iU", $html, $result);
$closedtags = $result[1];
$len_opened = count($openedtags);
// All tags are closed
if (count($closedtags) == $len_opened) {
return $html;
}
$openedtags = array_reverse($openedtags);
// Close tags
for ($i = 0; $i < $len_opened; $i++) {
if (!in_array($openedtags[$i], $closedtags)) {
if (!in_array($openedtags[$i], $arr_single_tags)) {
$html .= "</" . $openedtags[$i] . ">";
}
} else {
unset($closedtags[array_search($openedtags[$i], $closedtags)]);
}
}
return $html;
}
}
示例2: autoclose_tags_custom
function autoclose_tags_custom($content = '')
{
if (function_exists('tidy_repair_string')) {
return tidy_repair_string($content, array('clean' => true, 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'enclose-text' => true), 'utf8');
}
preg_match_all("#<([a-z]+)( .*)?(?!/)>#iU", $content, $result);
$openedtags = $result[1];
preg_match_all("#</([a-z]+)>#iU", $content, $result);
$closedtags = $result[1];
$len_opened = count($openedtags);
if (count($closedtags) == $len_opened) {
return $content;
}
$openedtags = array_reverse($openedtags);
for ($i = 0; $i < $len_opened; $i++) {
if (!in_array($openedtags[$i], $closedtags)) {
if (!in_array($openedtags[$i], array('img', 'br', 'hr', 'input', 'col', 'meta', 'link'))) {
$content .= '</' . $openedtags[$i] . '>';
}
} else {
unset($closedtags[array_search($openedtags[$i], $closedtags)]);
}
}
return $content;
}
示例3: DoFooter
function DoFooter($buffer)
{
global $noFooter, $timeStart, $queries, $overallTidy, $boardname, $title, $dblink, $ajax, $footerButtons, $footerExtensionsA, $footerExtensionsB;
if (!$noFooter) {
//if(function_exists("runBucket")) runBucket("footerButtons");
$footer = format("\n\t\t<div class=\"footer\">\n\t\t\tPowered by <a href=\"https://github.com/Dirbaio/ABXD\">AcmlmBoard XD</a>, version 2.2.6<br />\n\t\t\tBy Kawa, Mega-Mario, Nikolaj, et al<br />\n\t\t\tAcmlmBoard © Jean-François Lapointe<br />\n\t\t\t" . __("Page rendered in {0} seconds with {1}.") . "<br />\n\t\t\t{3}\n\n\t\t\t<a href=\"http://validator.w3.org/check?uri=referer\">\n\t\t\t\t<img src=\"img/xhtml10.png\" alt=\"Valid XHTML 1.0 Transitional\" />\n\t\t\t</a>\n\t\t\t<a href=\"http://jigsaw.w3.org/css-validator/\">\n\t\t\t\t<img src=\"img/css.png\" alt=\"Valid CSS!\" />\n\t\t\t</a>\n\t\t\t<a href=\"http://abxd.dirbaio.net/?page=downloads\">\n\t\t\t\t<img src=\"img/getabxd.png\" alt=\"Get a copy for yourself\" />\n\t\t\t</a>\n\t\t\t{2}\n\t\t</div>\n\t</div>\n</body>\n</html>\n", sprintf("%1.3f", usectime() - $timeStart), Plural($queries, __("MySQL query")), $footerButtons, __("<!-- English translation by Kawa -->"));
}
$boardTitle = htmlval($boardname);
if ($title != "") {
$boardTitle .= " » " . $title;
}
$raw = $buffer . $footerExtensionsA . $footer . $footerExtensionsB;
$raw = str_replace("<title>[[BOARD TITLE HERE]]</title>", "<title>" . $boardTitle . "</title>", $raw);
if (!$ajax) {
$raw = OptimizeLayouts($raw);
}
mysql_close($dblink);
if (!$overallTidy) {
return $raw;
}
$tidyConfig = array("show-body-only" => 0, "output-xhtml" => 1, "doctype" => "transitional", "logical-emphasis" => 1, "alt-text" => "", "drop-proprietary-attributes" => 1, "wrap" => 0, "preserve-entities" => 1, "indent" => 1, "input-encoding" => "utf8", "char-encoding" => "utf8", "output-encoding" => "utf8", "new-blocklevel-tags" => "video");
//if(function_exists(OptimizeLayouts))
// $raw = OptimizeLayouts($raw);
$clean = tidy_repair_string($raw, $tidyConfig);
$clean = str_replace("class=\"required", "required=\"required\" class=\"", $clean);
$textareaFixed = str_replace("\r", "", $clean);
$textareaFixed = str_replace(" </text", "</text", $textareaFixed);
$textareaFixed = str_replace("\n</text", "</text", $textareaFixed);
//$textareaFixed = str_replace("\n</text", "</text", $textareaFixed);
return $textareaFixed;
}
示例4: flush
public function flush()
{
if ($this->enabled && $this->userEnabled) {
$this->outputResponse->appendData(\tidy_repair_string($this->data, $this->config, 'utf8'));
}
$this->outputResponse->flush();
$dataBuffer = '';
}
示例5: __destruct2
function __destruct2()
{
$output = ob_get_clean();
$config = array('indent' => true, 'output-xhtml' => false, 'wrap' => false, 'hide-comments' => true, 'logical-emphasis' => true);
$output = tidy_repair_string($output, $config, 'utf8');
ob_start();
echo $output;
}
示例6: webifyFile
function webifyFile($file, $toc, $editions)
{
$filename = basename($file);
if (strpos('-book-', $filename)) {
return;
}
$toc = str_replace('<a href="' . $filename . '">', '<a href="' . $filename . '" class="active">', $toc);
$template = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'page.html');
$title = '';
$content = '';
$prev = '';
$next = '';
if ($filename !== 'index.html') {
if (strpos($filename, 'appendixes') === 0) {
$type = 'appendix';
} else {
if (strpos($filename, 'preface') === 0) {
$type = 'preface';
} else {
if (strpos($filename, 'pt') === 0) {
$type = 'part';
} else {
$type = 'chapter';
}
}
}
$buffer = file_get_contents($file);
$title = getSubstring($buffer, '<title>', '</title>', FALSE, FALSE);
$content = getSubstring($buffer, '<div class="' . $type . '"', '<div class="navfooter">', TRUE, FALSE);
$prev = getSubstring($buffer, '<link rel="prev" href="', '" title', FALSE, FALSE);
$next = getSubstring($buffer, '<link rel="next" href="', '" title', FALSE, FALSE);
if (!empty($prev)) {
$prev = '<a accesskey="p" href="' . $prev . '">Prev</a>';
}
if (!empty($next)) {
$next = '<a accesskey="n" href="' . $next . '">Next</a>';
}
} else {
$buffer = file_get_contents($file);
$title = getSubstring($buffer, '<title>', '</title>', FALSE, FALSE);
// $content = getSubstring($buffer, '<div class="titlepage"', '<div class="navfooter">', TRUE, FALSE);
$content = getSubstring($buffer, '<div class="titlepage"', '<hr>', TRUE, FALSE) . "\n</div>\n";
$prev = '';
$next = getSubstring($buffer, '<link rel="next" href="', '" title', FALSE, FALSE);
if (!empty($next)) {
$next = '<a accesskey="n" href="' . $next . '">Next</a>';
}
}
$buffer = str_replace(array('{title}', '{content}', '{toc}', '{editions}', '{prev}', '{next}'), array($title, $content, $toc, $editions, $prev, $next), $template);
if (function_exists('tidy_repair_string')) {
$buffer = tidy_repair_string($buffer, array('indent' => TRUE, 'output-xhtml' => TRUE, 'wrap' => 0), 'utf8');
}
file_put_contents($file, $buffer);
}
示例7: TidyLayout
function TidyLayout(&$header, &$footer)
{
return;
global $tidyconfig;
print "<!-- TIDYLAYOUT \n" . $header . "\n\n" . $footer;
$sep = "%%SNIP%%";
$pl = trim(tidy_repair_string($header . $sep . $footer, $tidyconfig));
$header = substr($pl, 0, strpos($pl, $sep));
$footer = substr($pl, strpos($pl, $sep) + strlen($sep));
print "\n\n" . $header . "\n\n" . $footer . "\n-->";
}
示例8: parse
private function parse($data)
{
$data = iconv('gbk', 'utf-8', $data);
$data = tidy_repair_string($data);
$doc = phpQuery::newDocument($data);
foreach (pq('tr') as $index => $tr) {
if ($index < 3) {
continue;
}
$item = array('date' => pq($tr)->find('td:eq(0)')->text(), 'tag' => pq($tr)->find('td:eq(2)')->text(), 'number' => pq($tr)->find('td:eq(3)')->text());
var_dump($item);
}
}
示例9: html2bb
function html2bb($html = '')
{
$html = nl2br(trim(stripslashes($html)));
$html = tidy_repair_string($html, array('output-xhtml' => true, 'show-body-only' => true, 'doctype' => 'strict', 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'lower-literals' => true, 'quote-ampersand' => true, 'wrap' => 0), 'utf8');
$html = trim($html);
$html = preg_replace('!<a(.*)href=(.+)>(.+)</a>!isU', '[url=$2]$3[/url]', $html);
$html = preg_replace('!<a(.*)>(.+)</a>!isU', '$2', $html);
$html = preg_replace('!<a(.*)href=(.+)></a>!isU', '[url]$2[/url]', $html);
$html = preg_replace('!<br(.*)>!isU', '\\r\\n', $html);
$html = str_replace('<p>', '\\r\\n', $html);
$html = str_replace('</p>', '\\r\\n', $html);
return htmlspecialchars($html);
}
示例10: cleanWrapped
/**
* Use the HTML tidy extension to use the tidy library in-process,
* saving the overhead of spawning a new process.
*
* @param string $text HTML to check
* @param bool $stderr Whether to read result from error status instead of output
* @param int &$retval Exit code (-1 on internal error)
* @return string|null
*/
protected function cleanWrapped($text, $stderr = false, &$retval = null)
{
if ($stderr) {
throw new Exception("\$stderr cannot be used with RaggettInternalHHVM");
}
$cleansource = tidy_repair_string($text, $this->config['tidyConfigFile'], 'utf8');
if ($cleansource === false) {
$cleansource = null;
$retval = -1;
} else {
$retval = 0;
}
return $cleansource;
}
示例11: parseData
/**
* @param Message $message
*
* @return Purchase[]
*/
protected function parseData(Message $message)
{
$dom = new \DOMDocument();
$dom->loadHTML(tidy_repair_string($message->getMessageBody(true)));
$nodes = $dom->getElementsByTagName('p');
$purchase = new Purchase\Purchase();
$matches = [];
preg_match('/((?:(?:[0-2]?\\d{1})|(?:[3][01]{1}))[-:\\/.](?:[0]?[1-9]|[1][012])[-:\\/.](?:(?:[1]{1}\\d{1}\\d{1}\\d{1})|(?:[2]{1}\\d{3})))(?![\\d])/', $nodes->item(2)->nodeValue, $matches);
$purchase->date = new Date(join('-', array_reverse(explode('/', $matches[1]))));
preg_match('/local: (.*?),/', str_replace('.', ',', str_replace("\n", ' ', $nodes->item(2)->nodeValue)), $matches);
$purchase->place = trim($matches[1]);
preg_match('/R\\$ (.*), no dia/', $nodes->item(2)->nodeValue, $matches);
$purchase->amount = (new Currency($matches[1]))->getValue();
return [$purchase];
}
示例12: filter
/**
* @author Hannes Gassert <hannes at mediagonal dot ch>
* @param string text to be filtered
*/
function filter($text)
{
/// Configuration for tidy. Feel free to tune for your needs, e.g. to allow
/// proprietary markup.
$tidyoptions = array('output-xhtml' => true, 'show-body-only' => true, 'tidy-mark' => false, 'drop-proprietary-attributes' => true, 'drop-font-tags' => true, 'drop-empty-paras' => true, 'indent' => true, 'quiet' => true);
/// Do a quick check using strpos to avoid unnecessary work
if (strpos($text, '<') === false) {
return $text;
}
/// If enabled: run tidy over the entire string
if (function_exists('tidy_repair_string')) {
$text = tidy_repair_string($text, $tidyoptions, 'utf8');
}
return $text;
}
示例13: html2bb
function html2bb($html = '')
{
$old = $html;
$html = trim(stripslashes($html));
$html = tidy_repair_string($html, array('output-xhtml' => true, 'show-body-only' => true, 'doctype' => 'strict', 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'lower-literals' => true, 'quote-ampersand' => true, 'wrap' => 0), 'utf8');
$html = trim($html);
$html = preg_replace('!<a(.*)href=(.+)>(.+)</a>!isU', '[url=$2]$3[/url]', $html);
$html = preg_replace('!(<|<)a(.*)href=(.+)(>|>)(.+)(<|<)/a(>|>)!isU', '[url=$3]$5[/url]', $html);
$html = preg_replace('!<a(.*)>(.+)</a>!isU', '$2', $html);
$html = preg_replace('!<a(.*)href=(.+)></a>!isU', '[url]$2[/url]', $html);
$html = preg_replace('!(<|<)br(.*)(>|>)!isU', "\r\n", $html);
$html = str_replace('<p>', "\r\n", $html);
$html = str_replace('</p>', "", $html);
return $html;
}
示例14: main
/**
* Main-Method for the Task
*
* @return void
* @throws BuildException
*/
public function main()
{
// check supplied attributes
$this->checkDir();
$this->checkFile();
// load file
$xml = simplexml_load_file($this->file);
// Just set them
$xml = $this->setLanguages($xml);
// write the new xml to the old xml file, using tidy if installed
if (function_exists('tidy_repair_string')) {
file_put_contents($this->file, tidy_repair_string($xml->asXML(), array('output-xml' => true, 'input-xml' => true, 'indent' => true, 'indent-spaces' => 4, 'wrap' => 0, 'vertical-space' => true, 'output-bom' => false, 'newline' => 'LF', 'char-encoding' => 'utf8')));
} else {
$xml->asXML($this->file);
}
}
示例15: tidyRepair
function tidyRepair($article, $easyset)
{
if ('com_content' != JRequest::getVar('option')) {
return;
}
if (!$article->introtext && !$article->fulltext) {
return;
}
if (function_exists('tidy_repair_string')) {
//Tidy Repair Text
$TidyConfig = array('indent' => TRUE, 'output-xhtml' => true, 'show-body-only' => true, 'wrap' => false);
$article->introtext = tidy_repair_string($article->introtext, $TidyConfig, 'utf8');
$article->fulltext = tidy_repair_string($article->fulltext, $TidyConfig, 'utf8');
} else {
require_once 'closeTags.php';
$article->introtext = closetags($article->introtext);
$article->fulltext = closetags($article->fulltext);
}
}