本文整理汇总了PHP中StringHelper::stripHtml方法的典型用法代码示例。如果您正苦于以下问题:PHP StringHelper::stripHtml方法的具体用法?PHP StringHelper::stripHtml怎么用?PHP StringHelper::stripHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringHelper
的用法示例。
在下文中一共展示了StringHelper::stripHtml方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createSlug
/**
* Creates a slug based on a given string.
*
* @param string $str
*
* @return string
*/
public static function createSlug($str)
{
// Remove HTML tags
$str = StringHelper::stripHtml($str);
// Convert to kebab case
$glue = craft()->config->get('slugWordSeparator');
$lower = !craft()->config->get('allowUppercaseInSlug');
$str = StringHelper::toKebabCase($str, $glue, $lower, false);
return $str;
}
示例2: getTableAttributeHtml
/**
* @inheritDoc IPreviewableFieldType::getTableAttributeHtml()
*
* @param mixed $value
*
* @return string
*/
public function getTableAttributeHtml($value)
{
$value = (string) $value;
return StringHelper::stripHtml($value);
}
示例3: _getElementExcerpt
/**
* Get an element's excerpt.
*
* @param array $element
*
* @return string
*/
private function _getElementExcerpt($element)
{
// What is our excerpt key?
$excerptKey = $this->_getCollectionSetting('excerptKey');
// Do we have an excerpt option?
if (empty($excerptKey) || !isset($element[$excerptKey])) {
return '';
}
// Get our full string
$fullString = $element[$excerptKey];
// Strip HTML from string
$fullString = StringHelper::stripHtml($fullString);
// Do we even have keywords?
if (!$this->_keywords) {
return $fullString;
}
// Excerpt settings
$prefix = $this->_excerptPrefix;
$suffix = $this->_excerptSuffix;
// Where are the keywords located?
$keywordsPosition = stripos($fullString, $this->_keywords);
// Find start
$extractStart = $keywordsPosition - $this->_charsBeforeKeywords;
if ($extractStart < 0) {
$extractStart = 0;
$prefix = '';
}
// Find end
$extractEnd = $keywordsPosition + strlen($this->_keywords) + $this->_charsAfterKeywords;
if ($extractEnd > strlen($fullString)) {
$extractEnd = strlen($fullString);
$suffix = '';
}
// Get excerpt!
$plainText = substr($fullString, $extractStart, $extractEnd - $extractStart);
$plainText = preg_replace("/(" . $this->_keywords . ")/i", "<strong>\$1</strong>", StringHelper::convertToUTF8($plainText));
// Handle CP request differently, otherwise while testing, the excerpt has become an object
if (craft()->request->isCpRequest()) {
return $prefix . $plainText . $suffix;
}
return new \Twig_Markup($prefix . $plainText . $suffix, craft()->templates->getTwig()->getCharset());
}