當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Tidy::cleanRepair方法代碼示例

本文整理匯總了PHP中Tidy::cleanRepair方法的典型用法代碼示例。如果您正苦於以下問題:PHP Tidy::cleanRepair方法的具體用法?PHP Tidy::cleanRepair怎麽用?PHP Tidy::cleanRepair使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Tidy的用法示例。


在下文中一共展示了Tidy::cleanRepair方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: fetchAds

 /**
  *	Gathers the advertisements from the remote page
  *	@param post		Array				The post data submitted by the form.
  *	@return			Array				The ads retrieved from the remote page.
  */
 public function fetchAds($post)
 {
     $this->_client->setUri($post['url']);
     $response = $this->_client->request('GET')->getBody();
     /**
      *	If the tidy class exists, attempt to cleanup the XML returned from the
      *	response requested from the remote site.
      */
     if (class_exists('tidy')) {
         $tidy = new Tidy('/dev/null', array('indent' => true, 'tab-size' => 4, 'output-encoding' => 'utf8', 'newline' => 'LF', 'output-xhtml' => true), 'utf8');
         $tidy->parseString($response);
         $tidy->cleanRepair();
         $response = $tidy->value;
     }
     /**
      *	Once we've attempted to clean up the retrieved HTML, attempt to parse the
      *	result in a DomDocument.
      */
     $xml = new DOMDocument('1.0', 'utf-8');
     $xml->loadHTML($response);
     $result = array();
     # Foreach of the anchor links in the page,
     foreach ($xml->getElementsByTagName('a') as $a) {
         # Get it's target HREF
         $href = $a->getAttribute('href');
         if (preg_match("/^http:\\/\\/([a-z\\-]+\\.)?{$post['ad']}.*\$/i", $href)) {
             # If a link's target points to the search query (the advertising site)
             $result[] = $href;
             # Append the result.
         }
     }
     return $result;
 }
開發者ID:aldimol,項目名稱:zf-sample,代碼行數:38,代碼來源:Ad.php

示例2: __construct

 public function __construct($content)
 {
     if (extension_loaded('tidy')) {
         // using the tiny php extension
         $tidy = new Tidy();
         $tidy->parseString($content, array('output-xhtml' => true, 'numeric-entities' => true, 'wrap' => 99999), 'utf8');
         $tidy->cleanRepair();
         $tidy = str_replace('xmlns="http://www.w3.org/1999/xhtml"', '', $tidy);
         $tidy = str_replace(' ', '', $tidy);
     } elseif (@shell_exec('which tidy')) {
         // using tiny through cli
         $CLI_content = escapeshellarg($content);
         $tidy = `echo {$CLI_content} | tidy -n -q -utf8 -asxhtml 2> /dev/null`;
         $tidy = str_replace('xmlns="http://www.w3.org/1999/xhtml"', '', $tidy);
         $tidy = str_replace(' ', '', $tidy);
     } else {
         // no tidy library found, hence no sanitizing
         $tidy = $content;
     }
     $this->simpleXML = @simplexml_load_string($tidy, 'SimpleXMLElement', LIBXML_NOWARNING);
     if (!$this->simpleXML) {
         throw new Exception('CSSContentParser::__construct(): Could not parse content.' . ' Please check the PHP extension tidy is installed.');
     }
     parent::__construct();
 }
開發者ID:hemant-chakka,項目名稱:awss,代碼行數:25,代碼來源:CSSContentParser.php

示例3: transformToHTML

 /**
  * Transforms an XML file into compatible XHTML based on the stylesheet
  * @param $xml XML DOM tree, or string filename
  * @return string HTML output
  * @todo Rename to transformToXHTML, as transformToHTML is misleading
  */
 public function transformToHTML($xml)
 {
     if (is_string($xml)) {
         $dom = new DOMDocument();
         $dom->load($xml);
     } else {
         $dom = $xml;
     }
     $out = $this->xsltProcessor->transformToXML($dom);
     // fudges for HTML backwards compatibility
     // assumes that document is XHTML
     $out = str_replace('/>', ' />', $out);
     // <br /> not <br/>
     $out = str_replace(' xmlns=""', '', $out);
     // rm unnecessary xmlns
     if (class_exists('Tidy')) {
         // cleanup output
         $config = array('indent' => true, 'output-xhtml' => true, 'wrap' => 80);
         $tidy = new Tidy();
         $tidy->parseString($out, $config, 'utf8');
         $tidy->cleanRepair();
         $out = (string) $tidy;
     }
     return $out;
 }
開發者ID:Jaaviieer,項目名稱:PrograWeb,代碼行數:31,代碼來源:HTMLXSLTProcessor.php

示例4: generateFromTokens

 /**
  * Generates HTML from an array of tokens.
  * @param $tokens Array of HTMLPurifier_Token
  * @param $config HTMLPurifier_Config object
  * @return Generated HTML
  */
 public function generateFromTokens($tokens)
 {
     if (!$tokens) {
         return '';
     }
     // Basic algorithm
     $html = '';
     for ($i = 0, $size = count($tokens); $i < $size; $i++) {
         if ($this->_scriptFix && $tokens[$i]->name === 'script' && $i + 2 < $size && $tokens[$i + 2] instanceof HTMLPurifier_Token_End) {
             // script special case
             // the contents of the script block must be ONE token
             // for this to work.
             $html .= $this->generateFromToken($tokens[$i++]);
             $html .= $this->generateScriptFromToken($tokens[$i++]);
         }
         $html .= $this->generateFromToken($tokens[$i]);
     }
     // Tidy cleanup
     if (extension_loaded('tidy') && $this->config->get('Output.TidyFormat')) {
         $tidy = new Tidy();
         $tidy->parseString($html, array('indent' => true, 'output-xhtml' => $this->_xhtml, 'show-body-only' => true, 'indent-spaces' => 2, 'wrap' => 68), 'utf8');
         $tidy->cleanRepair();
         $html = (string) $tidy;
         // explicit cast necessary
     }
     // Normalize newlines to system defined value
     $nl = $this->config->get('Output.Newline');
     if ($nl === null) {
         $nl = PHP_EOL;
     }
     if ($nl !== "\n") {
         $html = str_replace("\n", $nl, $html);
     }
     return $html;
 }
開發者ID:dobreapa,項目名稱:owasp-esapi-php,代碼行數:41,代碼來源:Generator.php

示例5: Tidy

	function __construct($content) {
		if(extension_loaded('tidy')) {
			// using the tiny php extension
			$tidy = new Tidy();
			$tidy->parseString(
				$content, 
				array(
					'output-xhtml' => true,
					'numeric-entities' => true,
				), 
				'utf8'
			);
			$tidy->cleanRepair();
			$tidy = str_replace('xmlns="http://www.w3.org/1999/xhtml"','',$tidy);
			$tidy = str_replace('&#160;','',$tidy);
		} elseif(`which tidy`) {
			// using tiny through cli
			$CLI_content = escapeshellarg($content);
			$tidy = `echo $CLI_content | tidy -n -q -utf8 -asxhtml 2> /dev/null`;
			$tidy = str_replace('xmlns="http://www.w3.org/1999/xhtml"','',$tidy);
			$tidy = str_replace('&#160;','',$tidy);
		} else {
			// no tidy library found, hence no sanitizing
			$tidy = $content;
		}
		
		
		
		$this->simpleXML = new SimpleXMLElement($tidy);
	}
開發者ID:neopba,項目名稱:silverstripe-book,代碼行數:30,代碼來源:CSSContentParser.php

示例6: _tidyFix

 /**
  * receive the html content, fix/format the dom tree and return it
  * 
  * @param string $content
  * @return string
  */
 protected function _tidyFix($content)
 {
     $config = ['input-xml' => true, 'output-xml' => true, 'wrap' => false];
     $tidy = new Tidy();
     $tidy->parseString($content, $config, 'utf8');
     $tidy->cleanRepair();
     $content = (string) $tidy;
     return $content;
 }
開發者ID:PavelPolyakov,項目名稱:parsing-with-php,代碼行數:15,代碼來源:index.php

示例7: beforeResponse

 public static function beforeResponse($request, $response)
 {
     if ($request['_format'] == 'html') {
         $tidy = new \Tidy();
         $tidy->parseString($response, array('wrap' => 200, 'indent' => true), 'utf8');
         $tidy->cleanRepair();
         $html = $tidy->html();
         $response = $html->value;
     }
     return $response;
 }
開發者ID:joshdavey,項目名稱:madeam,代碼行數:11,代碼來源:Tidy.php

示例8: formatHtml

 public function formatHtml($html, $charset = null, $charset_hint = null)
 {
     $html = $this->toUTF8($html, $charset, $charset_hint);
     $tidy = new Tidy();
     $config = array("hide-comments" => true);
     $tidy->parseString($html, $config, 'UTF8');
     $tidy->cleanRepair();
     $html = (string) $tidy;
     $html = $this->moveMetaContentTypeToTop($html);
     $html = $this->formatDocType($html);
     return $html;
 }
開發者ID:maalls,項目名稱:domdocument,代碼行數:12,代碼來源:Factory.php

示例9: Tidy

 function parse_html($html_code)
 {
     $this->html_code = $html_code;
     // Tidy HTML code
     $tidy = new Tidy();
     $tidy->parseString($html_code, $this->tidy_config, 'utf8');
     $tidy->cleanRepair();
     $this->tidy_code = $tidy->value;
     $this->dom = DOMDocument::loadXML($tidy->value);
     $this->dom->normalizeDocument();
     if ($this->dom == null) {
         trigger_error("Unable to parse XML Document!", E_USER_ERROR);
     }
 }
開發者ID:exhuma,項目名稱:libtex-php,代碼行數:14,代碼來源:libtex.php

示例10: formatTables

 public function formatTables($text)
 {
     $text = preg_replace_callback('%<div class="rvps(?:14|8)">\\n*<table.*?>([\\s\\S]*?)</table>\\n*</div>%u', function ($matches) {
         $table = '<table>' . $matches[1] . '</table>';
         $table = preg_replace('%(?:<p class="rvps(?:1|4|14)">)?<span class="rvts(?:9|15|23)">\\s*(.*?)\\s*</span>(?:</p>)?%u', '<b class="table-header">$1</b>', $table);
         $table = preg_replace('%<b class="table-header"><br></b>%u', '', $table);
         // rvps14 - rvps14
         // rvps14 - rvps11
         // rvps4 - rvps15
         $config = array('clean' => true, 'output-html' => true, 'show-body-only' => true, 'wrap' => 0, 'indent' => true);
         $tidy = new \Tidy();
         $tidy->parseString($table, $config, 'utf8');
         $tidy->cleanRepair();
         return $tidy . "\n";
     }, $text);
     return $text;
 }
開發者ID:RadaData,項目名稱:lawgrabber,代碼行數:17,代碼來源:ModernLawRenderer.php

示例11: read

 /**
  * Reads input and returns Tidy-filtered output.
  *
  * @param null $len
  *
  * @throws BuildException
  * @return the resulting stream, or -1 if the end of the resulting stream has been reached
  *
  */
 public function read($len = null)
 {
     if (!class_exists('Tidy')) {
         throw new BuildException("You must enable the 'tidy' extension in your PHP configuration in order to use the Tidy filter.");
     }
     if (!$this->getInitialized()) {
         $this->_initialize();
         $this->setInitialized(true);
     }
     $buffer = $this->in->read($len);
     if ($buffer === -1) {
         return -1;
     }
     $config = $this->getDistilledConfig();
     $tidy = new Tidy();
     $tidy->parseString($buffer, $config, $this->encoding);
     $tidy->cleanRepair();
     return tidy_get_output($tidy);
 }
開發者ID:TheTypoMaster,項目名稱:SPHERE-Framework,代碼行數:28,代碼來源:TidyFilter.php

示例12: transformToHTML

 /**
  * Transforms an XML file into HTML based on the stylesheet
  * @param $xml XML DOM tree
  */
 public function transformToHTML($xml)
 {
     $out = $this->xsltProcessor->transformToXML($xml);
     // fudges for HTML backwards compatibility
     $out = str_replace('/>', ' />', $out);
     // <br /> not <br/>
     $out = str_replace(' xmlns=""', '', $out);
     // rm unnecessary xmlns
     $out = str_replace(' xmlns="http://www.w3.org/1999/xhtml"', '', $out);
     // rm unnecessary xmlns
     if (class_exists('Tidy')) {
         // cleanup output
         $config = array('indent' => true, 'output-xhtml' => true, 'wrap' => 80);
         $tidy = new Tidy();
         $tidy->parseString($out, $config, 'utf8');
         $tidy->cleanRepair();
         $out = (string) $tidy;
     }
     return $out;
 }
開發者ID:hasshy,項目名稱:sahana-tw,代碼行數:24,代碼來源:HTMLXSLTProcessor.php

示例13: loadHtml

 protected function loadHtml($uri)
 {
     if (preg_match('/^https?:/i', $uri) === 0) {
         $uri = $this->config->getBaseHref() . $uri;
     }
     $curl = curl_init($uri);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     $html = curl_exec($curl);
     $this->request_info = curl_getinfo($curl);
     curl_close($curl);
     $this->location = $uri;
     $tidy = new Tidy();
     $tidy->parseString($html, array('output-xhtml' => true, 'char-encoding' => 'utf8', 'numeric-entities' => true), 'utf8');
     $tidy->cleanRepair();
     $this->document = new DOMDocument();
     $this->document->resolveExternals = true;
     $this->document->loadXml($tidy);
     $this->xpath = new DOMXPath($this->document);
     $this->xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
     $this->xpath->registerNamespace('html', 'http://www.w3.org/1999/xhtml');
 }
開發者ID:nburka,項目名稱:blorgy,代碼行數:21,代碼來源:FeedTestCase.php

示例14: MyCurl

    $response['message'] = "";
    //use php's filter to check for a valid url
    if (!filter_var($_POST['url'], FILTER_VALIDATE_URL) === false) {
        $url = $_POST['url'];
        $curl = new MyCurl($url);
        $curl->createCurl();
        $response['code'] = $curl->getHttpStatus();
        $response['message'] = HttpCodes::getType($response['code']);
        $html = $curl->__toString();
        if (!is_string($html)) {
            $response['message'] = "Page Could not be loaded, check the domain. Nothing was returned.";
        } else {
            $tidy = new Tidy();
            //load page into tidy object, set options, and clean html
            $tidy->parseString($html, array('indent' => 2, 'output-xhtml' => true));
            $tidy->cleanRepair();
            //html is now nicely indented
            $html = (string) $tidy;
            //count the tags and get the result in a $tag => $count array
            $tagCount = countTags($html);
            $response['tagCount'] = $tagCount;
            $response['html'] = htmlentities($html);
        }
    } else {
        $response['message'] = $_POST['url'] . " is not a valid URL";
    }
    header('Content-Type: application/json');
    echo json_encode($response);
} else {
    //load the base view, located at ../views/base.php
    View::load("base");
開發者ID:danicheman,項目名稱:urlchecker,代碼行數:31,代碼來源:index.php

示例15: tidyToXml

function tidyToXml($htmlTagSoup)
{
    // Create the Tidy object
    $tidy = new Tidy();
    // Parse the HTML into memory, turning on the option to convert to
    // XHTML as part of the tidying process
    $tidy->parseString($htmlTagSoup, array('output-xhtml' => true));
    // Do the tidying
    $tidy->cleanRepair();
    // And get the tidied version as a string
    $tidied_xml = tidy_get_output($tidy);
    // Opinions seem to differ as to whether the non-breaking space
    // entity '&nbsp;' is predeclared as part of XHTML.  Tidy thinks it
    // is, and so leaves it alone, while the XML parser we're about to
    // use on this string thinks otherwise.  So replace any occurrences
    // of it with its numeric equivalent (which doesn't need to be
    // declared).
    return str_replace('&nbsp;', '&#160;', $tidied_xml);
}
開發者ID:markjreed,項目名稱:reedville,代碼行數:19,代碼來源:findspells.php


注:本文中的Tidy::cleanRepair方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。