本文整理汇总了PHP中tidy::body方法的典型用法代码示例。如果您正苦于以下问题:PHP tidy::body方法的具体用法?PHP tidy::body怎么用?PHP tidy::body使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tidy
的用法示例。
在下文中一共展示了tidy::body方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createContentElements
protected function createContentElements(&$objItem)
{
if ($objItem->tl_content) {
// need to wrap <p> around text for contao
$tidyConfig = array('enclose-text' => true, 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'quote-ampersand' => true, 'clean' => false);
$bodyText = '<!DOCTYPE html><head><title></title></head><body>' . $objItem->tl_content . '</body></html>';
// $bodyText = $this->convert_external_link_tags($bodyText);
// $bodyText = $this->convert_internal_link_tags($bodyText);
$bodyText = $this->nl2p($bodyText);
$tidy = new \tidy();
$tidy->parseString($bodyText, $tidyConfig, $GLOBALS['TL_CONFIG']['dbCharset']);
$body = $tidy->body();
$objContent = new \ContentModel();
$objContent->text = trim(str_replace(array('<body>', '</body>'), '', $body));
$objContent->text = preg_replace("/<img[^>]+\\>/i", "", $objContent->text);
// strip images
// create links from text
$objContent->text = preg_replace('!(\\s|^)((https?://|www\\.)+[a-z0-9_./?=&-]+)!i', ' <a href="http://$2" target="_blank">$2</a>', $objContent->text);
// replace <b> by <strong>
$objContent->text = preg_replace('!<b(.*?)>(.*?)</b>!i', '<strong>$2</strong>', $objContent->text);
// replace emails with inserttags
$objContent->text = preg_replace('/([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\\.([A-Z]{2,4})(\\((.+?)\\))?/i', "{{email::\$1@\$2.\$3}}", $objContent->text);
// strip not allowed tags
$objContent->text = strip_tags($objContent->text, \Config::get('allowedTags'));
$objContent->text = $this->stripAttributes($objContent->text, array('style', 'class', 'id'));
$objContent->ptable = static::$strTable;
$objContent->pid = $objItem->id;
$objContent->sorting = 16;
$objContent->tstamp = time();
$objContent->type = 'text';
$objContent->save();
}
}
示例2: toPlainText
/**
* @return string
*/
public function toPlainText(Io_Charset $outputCharset_ = null)
{
if (null === $outputCharset_) {
$outputCharset_ = $this->m_charset;
}
$html = html_entity_decode($this->m_value, ENT_QUOTES, $this->m_charset->name());
$tidy = new \tidy();
$tidy->parseString($html, ['char-encoding' => $this->m_charset->name(), 'input-encoding' => $this->m_charset->name(), 'output-encoding' => $outputCharset_->name()]);
$string = '';
$this->nodeToPlainText($tidy->body(), $string);
return $string;
}
示例3: createContentElements
protected function createContentElements(&$objItem)
{
if ($objItem->tl_content) {
// need to wrap <p> around text for contao
$tidyConfig = array('enclose-text' => true, 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'quote-ampersand' => true, 'clean' => false, 'wrap-attributes' => false, 'wrap' => 500);
$bodyText = '<!DOCTYPE html><head><title></title></head><body>' . $objItem->tl_content . '</body></html>';
// $bodyText = $this->convert_external_link_tags($bodyText);
// $bodyText = $this->convert_internal_link_tags($bodyText);
$bodyText = $this->nl2p($bodyText);
$tidy = new \tidy();
$tidy->parseString($bodyText, $tidyConfig, $GLOBALS['TL_CONFIG']['dbCharset']);
$body = $tidy->body();
$objContent = new \ContentModel();
$objContent->text = urldecode($objContent->text);
// decode, otherwise link and email regex wont work
$objContent->text = trim(str_replace(array('<body>', '</body>'), '', $body));
$objContent->text = preg_replace("/<img[^>]+\\>/i", "", $objContent->text);
// strip images
// remove inline styles
$objContent->text = preg_replace('#(<[a-z ]*)(style=("|\')(.*?)("|\'))([a-z ]*>)#', '\\1\\6', $objContent->text);
// remove white space from empty tags
$objContent->text = preg_replace('#(<[a-z]*)(\\s+)>#', '$1>', $objContent->text);
// create links from text
$objContent->text = preg_replace('!(\\s|^)((https?://|www\\.)+[a-z0-9_./?=&-]+)!i', ' <a href="http://$2" target="_blank">$2</a>', $objContent->text);
// replace <b> by <strong>
$objContent->text = preg_replace('!<b(.*?)>(.*?)</b>!i', '<strong>$2</strong>', $objContent->text);
// replace plain email text with inserttags
$objContent->text = preg_replace('/([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\\.([A-Z]{2,4})(\\((.+?)\\))?(?![^<]*>)(?![^>]*<)/i', "{{email::\$1@\$2.\$3}}", $objContent->text);
// replace email links with inserttags
$objContent->text = preg_replace('/<a.*href=[\'|"]mailto:([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\\.([A-Z]{2,4})(\\((.+?)\\))?[\'|"].*>(.*)<\\/a>/i', "{{email::\$1@\$2.\$3}}", $objContent->text);
// strip not allowed tags
$objContent->text = strip_tags($objContent->text, \Config::get('allowedTags'));
$objContent->text = $this->stripAttributes($objContent->text, array('style', 'class', 'id'));
$objContent->ptable = $this->dbTargetTable;
$objContent->pid = $objItem->id;
$objContent->sorting = 16;
$objContent->tstamp = time();
$objContent->type = 'text';
$objContent->save();
}
}
示例4: array
<?php
header("Content-type: application/xml");
if (isset($_REQUEST['x'])) {
echo file_get_contents("../../{$_REQUEST['x']}");
exit;
}
$html = str_replace("></", "><!--c--></", $GLOBALS["HTTP_RAW_POST_DATA"]);
$config = array("indent" => false, "output-xhtml" => true, "wrap" => 200);
$tidy = new tidy();
$tidy->parseString($html, $config, "utf8");
$tidy->cleanRepair();
echo $tidy->body()->child[0]->value;
示例5: dirname
<?php
//encoding=utf-8
header("Content-type: application/xml");
$html = $GLOBALS["HTTP_RAW_POST_DATA"];
$dataURI = $_REQUEST["dataURI"];
$dir = dirname(__FILE__);
$baseDir = substr($dir, 0, strpos($dir, "component"));
$config = array("indent" => false, "output-xhtml" => true, "wrap" => 200);
$tidy = new tidy();
$tidy->parseString($html, $config, "utf8");
$tidy->cleanRepair();
$content = str_replace(" ", " ", $tidy->body()->child[0]->value);
$content = "<div xmlns=\"http://www.w3.org/1999/xhtml\"" . substr($content, 4);
$contentDoc = new DOMDocument("1.0", "UTF-8");
$contentDoc->loadXML($content);
$xslDoc = new DOMDocument();
$xslDoc->load("setter-header.xsl");
$xslt = new XSLTProcessor();
$xslt->importStylesheet($xslDoc);
$result = $xslt->transformToXML($contentDoc);
print $result;
$fp = fopen($baseDir . $dataURI, "w");
fwrite($fp, $result);
fclose($fp);
示例6: dirname
<?php
//encoding=utf-8
header("Content-type: application/xml");
$html = $GLOBALS["HTTP_RAW_POST_DATA"];
$dataURI = $_REQUEST["dataURI"];
$dir = dirname(__FILE__);
$baseDir = substr($dir, 0, strpos($dir, "component"));
$config = array("indent" => false, "output-xhtml" => true, "wrap" => 200);
$tidy = new tidy();
$tidy->parseString($html, $config, "utf8");
$tidy->cleanRepair();
$xmlDoc = new DOMDocument("1.0", "utf-8");
$xmlDoc->loadXML(str_replace(" ", " ", $tidy->body()->child[0]->value));
$xslt = new XSLTProcessor();
$xslDoc = new DOMDocument();
$xslDoc->load('setter-article.xsl');
$xslt->importStylesheet($xslDoc);
$result = $xslt->transformToXML($xmlDoc);
print $result;
$fp = fopen($baseDir . $dataURI, "w");
fwrite($fp, $result);
fclose($fp);