本文整理汇总了PHP中Texy::freezeSpaces方法的典型用法代码示例。如果您正苦于以下问题:PHP Texy::freezeSpaces方法的具体用法?PHP Texy::freezeSpaces怎么用?PHP Texy::freezeSpaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texy
的用法示例。
在下文中一共展示了Texy::freezeSpaces方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startTag
/**
* Returns element's start tag.
* @return string
*/
public function startTag()
{
if (!$this->name) {
return '';
}
$s = '<' . $this->name;
if (is_array($this->attrs)) {
foreach ($this->attrs as $key => $value) {
// skip NULLs and false boolean attributes
if ($value === NULL || $value === FALSE) {
continue;
}
// true boolean attribute
if ($value === TRUE) {
// in XHTML must use unminimized form
if (self::$xhtml) {
$s .= ' ' . $key . '="' . $key . '"';
} else {
$s .= ' ' . $key;
}
continue;
} elseif (is_array($value)) {
// prepare into temporary array
$tmp = NULL;
foreach ($value as $k => $v) {
// skip NULLs & empty string; composite 'style' vs. 'others'
if ($v == NULL) {
continue;
} elseif (is_string($k)) {
$tmp[] = $k . ':' . $v;
} else {
$tmp[] = $v;
}
}
if (!$tmp) {
continue;
}
$value = implode($key === 'style' ? ';' : ' ', $tmp);
} else {
$value = (string) $value;
}
// add new attribute
$value = str_replace(array('&', '"', '<', '>', '@'), array('&', '"', '<', '>', '@'), $value);
$s .= ' ' . $key . '="' . Texy::freezeSpaces($value) . '"';
}
}
// finish start tag
if (self::$xhtml && $this->isEmpty) {
return $s . ' />';
}
return $s . '>';
}
示例2: cb
private function cb($matches)
{
list(, $mText, $mComment, $mEnd, $mTag, $mAttr, $mEmpty) = $matches;
$s = '';
if ($mText !== '') {
$item = reset($this->tagStack);
if ($item && !isset($item['dtdContent']['%DATA'])) {
} elseif (!empty($this->tagUsed['pre']) || !empty($this->tagUsed['textarea']) || !empty($this->tagUsed['script'])) {
$s = Texy::freezeSpaces($mText);
} else {
$s = preg_replace('#[ \\n]+#', ' ', $mText);
}
}
if ($mComment) {
return $s . '<' . Texy::freezeSpaces($mComment) . '>';
}
$mEmpty = $mEmpty || isset(TexyHtml::$emptyElements[$mTag]);
if ($mEmpty && $mEnd) {
return $s;
}
if ($mEnd) {
if (empty($this->tagUsed[$mTag])) {
return $s;
}
$tmp = array();
$back = TRUE;
foreach ($this->tagStack as $i => $item) {
$tag = $item['tag'];
$s .= $item['close'];
$this->space -= $item['indent'];
$this->tagUsed[$tag]--;
$back = $back && isset(TexyHtml::$inlineElements[$tag]);
unset($this->tagStack[$i]);
if ($tag === $mTag) {
break;
}
array_unshift($tmp, $item);
}
if (!$back || !$tmp) {
return $s;
}
$item = reset($this->tagStack);
if ($item) {
$dtdContent = $item['dtdContent'];
} else {
$dtdContent = $this->baseDTD;
}
if (!isset($dtdContent[$tmp[0]['tag']])) {
return $s;
}
foreach ($tmp as $item) {
$s .= $item['open'];
$this->space += $item['indent'];
$this->tagUsed[$item['tag']]++;
array_unshift($this->tagStack, $item);
}
} else {
$dtdContent = $this->baseDTD;
if (!isset($this->texy->dtd[$mTag])) {
$allowed = TRUE;
$item = reset($this->tagStack);
if ($item) {
$dtdContent = $item['dtdContent'];
}
} else {
foreach ($this->tagStack as $i => $item) {
$dtdContent = $item['dtdContent'];
if (isset($dtdContent[$mTag])) {
break;
}
$tag = $item['tag'];
if ($item['close'] && (!isset(TexyHtml::$optionalEnds[$tag]) && !isset(TexyHtml::$inlineElements[$tag]))) {
break;
}
$s .= $item['close'];
$this->space -= $item['indent'];
$this->tagUsed[$tag]--;
unset($this->tagStack[$i]);
$dtdContent = $this->baseDTD;
}
$allowed = isset($dtdContent[$mTag]);
if ($allowed && isset(TexyHtml::$prohibits[$mTag])) {
foreach (TexyHtml::$prohibits[$mTag] as $pTag) {
if (!empty($this->tagUsed[$pTag])) {
$allowed = FALSE;
break;
}
}
}
}
if ($mEmpty) {
if (!$allowed) {
return $s;
}
if ($this->xml) {
$mAttr .= " /";
}
$indent = $this->indent && empty($this->tagUsed['pre']) && empty($this->tagUsed['textarea']);
if ($indent && $mTag === 'br') {
return rtrim($s) . '<' . $mTag . $mAttr . ">\n" . str_repeat("\t", max(0, $this->space - 1)) . "";
//.........这里部分代码省略.........
示例3: cb
/**
* Callback function: <tag> | </tag> | ....
* @return string
*/
private function cb($matches)
{
// html tag
list(, $mText, $mComment, $mEnd, $mTag, $mAttr, $mEmpty) = $matches;
// [1] => text
// [1] => !-- comment --
// [2] => /
// [3] => TAG
// [4] => ... (attributes)
// [5] => / (empty)
$s = '';
// phase #1 - stuff between tags
if ($mText !== '') {
$item = reset($this->tagStack);
// text not allowed?
if ($item && !isset($item['dtdContent']['%DATA'])) {
} elseif (!empty($this->tagUsed['pre']) || !empty($this->tagUsed['textarea']) || !empty($this->tagUsed['script'])) {
$s = Texy::freezeSpaces($mText);
} else {
$s = preg_replace('#[ \\n]+#', ' ', $mText);
}
}
// phase #2 - HTML comment
if ($mComment) {
return $s . '<' . Texy::freezeSpaces($mComment) . '>';
}
// phase #3 - HTML tag
$mEmpty = $mEmpty || isset(TexyHtml::$emptyElements[$mTag]);
if ($mEmpty && $mEnd) {
return $s;
}
// bad tag; /end/
if ($mEnd) {
// end tag
// has start tag?
if (empty($this->tagUsed[$mTag])) {
return $s;
}
// autoclose tags
$tmp = array();
$back = TRUE;
foreach ($this->tagStack as $i => $item) {
$tag = $item['tag'];
$s .= $item['close'];
$this->space -= $item['indent'];
$this->tagUsed[$tag]--;
$back = $back && isset(TexyHtml::$inlineElements[$tag]);
unset($this->tagStack[$i]);
if ($tag === $mTag) {
break;
}
array_unshift($tmp, $item);
}
if (!$back || !$tmp) {
return $s;
}
// allowed-check (nejspis neni ani potreba)
$item = reset($this->tagStack);
if ($item) {
$dtdContent = $item['dtdContent'];
} else {
$dtdContent = $this->baseDTD;
}
if (!isset($dtdContent[$tmp[0]['tag']])) {
return $s;
}
// autoopen tags
foreach ($tmp as $item) {
$s .= $item['open'];
$this->space += $item['indent'];
$this->tagUsed[$item['tag']]++;
array_unshift($this->tagStack, $item);
}
} else {
// start tag
$dtdContent = $this->baseDTD;
if (!isset($this->texy->dtd[$mTag])) {
// unknown (non-html) tag
$allowed = TRUE;
$item = reset($this->tagStack);
if ($item) {
$dtdContent = $item['dtdContent'];
}
} else {
// optional end tag closing
foreach ($this->tagStack as $i => $item) {
// is tag allowed here?
$dtdContent = $item['dtdContent'];
if (isset($dtdContent[$mTag])) {
break;
}
$tag = $item['tag'];
// auto-close hidden, optional and inline tags
if ($item['close'] && (!isset(TexyHtml::$optionalEnds[$tag]) && !isset(TexyHtml::$inlineElements[$tag]))) {
break;
}
//.........这里部分代码省略.........