当前位置: 首页>>代码示例>>PHP>>正文


PHP Tidy::repairString方法代码示例

本文整理汇总了PHP中Tidy::repairString方法的典型用法代码示例。如果您正苦于以下问题:PHP Tidy::repairString方法的具体用法?PHP Tidy::repairString怎么用?PHP Tidy::repairString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tidy的用法示例。


在下文中一共展示了Tidy::repairString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadFeed

 public function loadFeed()
 {
     if (!isset(RSSFilter::$feeds[$this->A("RSSFilterFeed")])) {
         RSSFilter::$feeds[$this->A("RSSFilterFeed")] = "<phynx></phynx>";
         $content = @file_get_contents($this->A("RSSFilterFeed"));
         if ($content === false) {
             throw new Exception($this->A("RSSFilterFeed") . " could not be loaded!");
         }
         $content = str_replace("", "", $content);
         try {
             libxml_use_internal_errors(true);
             RSSFilter::$feeds[$this->A("RSSFilterFeed")] = new SimpleXMLElement($content);
         } catch (Exception $e) {
             try {
                 $config = array('indent' => true, 'clean' => true, 'input-xml' => true, 'output-xml' => true, 'wrap' => false);
                 $tidy = new Tidy();
                 $xml = $tidy->repairString($content, $config);
                 RSSFilter::$feeds[$this->A("RSSFilterFeed")] = new SimpleXMLElement($xml);
             } catch (ClassNotFoundException $e) {
                 throw new Exception($this->A("RSSFilterFeed") . " contains errors, but Tidy not found!");
             } catch (Exception $e) {
                 #$errors = "";
                 #foreach(libxml_get_errors() as $error)
                 #	print_r($error->message);
                 throw new Exception($this->A("RSSFilterFeed") . " contained errors even Tidy could not fix!");
             }
             #$errors = "";
             #foreach(libxml_get_errors() as $error)
             #	print_r($error->message);
             #throw new Exception($this->A("RSSFilterFeed"));
         }
     }
 }
开发者ID:nemiah,项目名称:trinityDB,代码行数:33,代码来源:RSSFilter.class.php

示例2: beautifyHtml

 public static function beautifyHtml($html, $config = array("output-xhtml" => true, "char-encoding" => "utf8", "indent" => true, "indent-spaces" => 4, "wrap" => 0))
 {
     if (!Ajde_Core_Autoloader::exists('Tidy')) {
         throw new Ajde_Exception('Class Tidy not found', 90023);
     }
     $tidy = new Tidy();
     // http://bugs.php.net/bug.php?id=35647
     return $tidy->repairString($html, $config, 'utf8');
 }
开发者ID:nabble,项目名称:updatemybrowser-v1,代码行数:9,代码来源:Beautifier.php

示例3: beautifyHtml

 public static function beautifyHtml($html, $config = ['output-xhtml' => true, 'char-encoding' => 'utf8', 'indent' => true, 'indent-spaces' => 4, 'wrap' => 0])
 {
     if (!class_exists('Tidy')) {
         throw new Ajde_Exception('Class Tidy not found', 90023);
     }
     $tidy = new Tidy();
     // tidy does not produce valid utf8 when the encoding is specified in the config
     // so we provide a third parameter, 'utf8' to fix this
     // @see http://bugs.php.net/bug.php?id=35647
     return $tidy->repairString($html, $config, 'utf8');
 }
开发者ID:nabble,项目名称:ajde,代码行数:11,代码来源:Beautifier.php

示例4: htmlFixSafe

 /**
  * 功能:清理未闭合的标签  商品存储的时候使用  要修改联系侯保法
  * 备注:需要php开启这个扩展php_tidy.dll
  * @param unknown_type $data    要处理的数据,可以是数据或字符串
  * @param unknown_type $encode    文字编码,默认是utf8
  * @return unknown    处理好的数据
  */
 public static function htmlFixSafe($data, $encode = 'utf8')
 {
     if (empty($data)) {
         return '';
     }
     $tidyConfig = array('indent' => false, 'output-xhtml' => true, 'show-body-only' => true, 'wrap' => 200, 'vertical-space' => 2);
     $tidyObj = new \Tidy();
     if (is_array($data)) {
         foreach ($data as $key => $value) {
             $data[$key] = self::htmlFixSafe($value);
         }
     } else {
         $data = $tidyObj->repairString($data, $tidyConfig, $encode);
     }
     return $data;
 }
开发者ID:tianyunchong,项目名称:php,代码行数:23,代码来源:StringHelper.php

示例5: closetags

 function closetags($html)
 {
     if (class_exists('Tidy')) {
         $tidy = new Tidy();
         $clean = $tidy->repairString($html, array('output-xml' => true, 'input-xml' => true));
         return $clean;
     }
     preg_match_all('#<(?!meta|img|br|hr|input\\b)\\b([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result);
     $openedtags = $result[1];
     preg_match_all('#</([a-z]+)>#iU', $html, $result);
     $closedtags = $result[1];
     $len_opened = count($openedtags);
     if (count($closedtags) == $len_opened) {
         return $html;
     }
     $openedtags = array_reverse($openedtags);
     for ($i = 0; $i < $len_opened; $i++) {
         if (!in_array($openedtags[$i], $closedtags)) {
             $html .= '</' . $openedtags[$i] . '>';
         } else {
             unset($closedtags[array_search($openedtags[$i], $closedtags)]);
         }
     }
     return $html;
 }
开发者ID:aldegtyarev,项目名称:stelsvelo,代码行数:25,代码来源:loader.php

示例6: onFunction

 function onFunction($matches, $s)
 {
     $fns = explode('||', $matches[2]);
     for ($i = count($fns) - 1; $i >= 0; $i--) {
         $fn = explode(',', $fns[$i]);
         switch ($fn[0]) {
             case 'cleanhtml':
                 $s = strip_tags($s, '<p><a><b><br><br/><i>');
                 break;
             case 'removehtml':
                 $s = strip_tags($s);
                 break;
             case 'splitbychars':
                 $s = substr($s, $fn[1], $fn[2]);
                 break;
             case 'splitbywords':
                 $len = strlen($s);
                 $pos = $fn[2] > $len ? $len : strpos($s, ' ', $fn[2]);
                 if ($pos === false) {
                     $pos = $len;
                 }
                 $s = substr($s, 0, $pos);
                 break;
             case 'findimage':
                 $index = isset($fn[1]) ? intval($fn[1]) - 1 : 0;
                 preg_match_all('/(<img.*?src=[\'"](.*?)[\'"][^>]+>)|(background(-image)??\\s*?:.*?url\\((["|\']?)?(.+?)(["|\']?)?\\))/i', $s, $r);
                 if (isset($r[2]) && !empty($r[2][$index])) {
                     $s = $r[2][$index];
                 } else {
                     if (isset($r[6]) && !empty($r[6][$index])) {
                         $s = trim($r[6][$index], "'\" \t\n\r\v");
                     } else {
                         $s = '';
                     }
                 }
                 break;
         }
     }
     if ($i !== -1) {
         if ($this->_tidy) {
             $tidy = new Tidy();
             return $tidy->repairString($s, array('show-body-only' => true, 'input-encoding' => $this->_tidyInputEncoding, 'output-encoding' => $this->_tidyOutputEncoding));
         }
     }
     return $this->closetags($s);
 }
开发者ID:JonathanAJ,项目名称:Seara-da-Ciencia-UFC,代码行数:46,代码来源:generator.php

示例7: setupEnvironment

 private function setupEnvironment()
 {
     global $gDatabase, $cDatabaseConnectionString, $cMyDotCnfFile, $cDatabaseModule, $cIncludePath, $cLoggerName, $gLogger;
     set_exception_handler(array("Hotel", "exceptionHandler"));
     // check all the required PHP extensions are enabled on this SAPI
     $this->checkPhpExtensions();
     // start output buffering before anything is sent to the browser.
     ob_start();
     // not caught by the autoloader :(
     require_once 'smarty/Smarty.class.php';
     // many exceptions defined in one file, let's not clutter stuff.
     // This ofc breaks the autoloading, so let's include them all now.
     // (Depends on some smarty stuff)
     require_once $cIncludePath . "/_Exceptions.php";
     spl_autoload_register("Hotel::autoLoader");
     Session::start();
     $gLogger = new $cLoggerName();
     $gLogger->log("Initialising logger!");
     if (!extension_loaded($cDatabaseModule)) {
         throw new ExtensionUnavailableException($cDatabaseModule);
     }
     $mycnf = parse_ini_file($cMyDotCnfFile);
     $gDatabase = new Database($cDatabaseConnectionString, $mycnf["user"], $mycnf["password"]);
     // tidy up sensitive data we don't want lying around.
     unset($mycnf);
     // use exceptions on failed database stuff
     $gDatabase->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     // can we tidy up the output with tidy before we send it?
     if (extension_loaded("tidy")) {
         // Yes!
         global $cUseTidy;
         if ($cUseTidy) {
             // register a new function to hook into the output bit
             Hooks::register("BeforeOutputSend", function ($params) {
                 $tidy = new Tidy();
                 global $cTidyOptions;
                 return $tidy->repairString($params[0], $cTidyOptions, "utf8");
             });
         }
     }
     global $gCookieJar;
     $gCookieJar = array();
 }
开发者ID:vulnerabilityCode,项目名称:hotel-system,代码行数:43,代码来源:Hotel.php

示例8: htmlentities

<?php

session_start();
include "dbInfo.php";
$conn = mysqli_connect("localhost", DBUSERNAME, DBPASSWORD, DB);
$title = htmlentities($_POST['title'], ENT_QUOTES);
$tidy = new Tidy();
$html = $_POST["content"];
$content = $tidy->repairString($html, array("output-xml" => true, "input-xml" => true));
$username = $_SESSION["username"];
$date = getdate();
$datef = $date['year'] . "-" . $date['mon'] . "-" . $date['mday'];
$command = "INSERT INTO `" . DB . "`.`Posts` (`ID`, `Title`, `Content`, `Author`, `Date`) VALUES (NULL, '{$title}', '{$content}', '{$username}', '{$datef}')";
if (mysqli_query($conn, $command)) {
    header("location:../index.php");
}
开发者ID:TheSchraube,项目名称:Blog,代码行数:16,代码来源:add.php

示例9: repair

 /**
  * Repair a XML string to a valid XML.
  *
  * Input :
  * - <m   t="my message" u="123456789"i="626"   />
  *
  * Output:
  * - <m t="my message" u="123456789" i="626" />
  *
  * @param string $input The XML to repair.
  * @param array $options The options to use with the Tidy class.
  *
  * @return string
  *
  * @throws \Mars\Utility\Exception\XmlException
  */
 public static function repair($input, array $options = [])
 {
     $defaults = ['indent' => true, 'input-xml' => true, 'output-xml' => true, 'wrap' => false];
     $options += $defaults;
     if (!extension_loaded('tidy')) {
         throw new XmlException('The extension Tidy is not loaded.');
     }
     $tidy = new \Tidy();
     return $tidy->repairString($input, $options);
 }
开发者ID:xety,项目名称:marsbot,代码行数:26,代码来源:Xml.php


注:本文中的Tidy::repairString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。