本文整理匯總了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());
}