本文整理汇总了PHP中str::convert方法的典型用法代码示例。如果您正苦于以下问题:PHP str::convert方法的具体用法?PHP str::convert怎么用?PHP str::convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类str
的用法示例。
在下文中一共展示了str::convert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertEncoding
/**
* Convert a character from UTF-8 to UTF-16BE
*
* @param string $char
* @return string
*/
public static function convertEncoding($char)
{
return str::convert($char, 'UTF-16BE', 'UTF-8');
}
示例2: function
* @param Field $field The calling Kirby Field instance.
* @param array $tags List of html tags to allow.
*
* @return Field
*/
field::$methods['safeMarkdown'] = function ($field, $tags = null) {
// Sensible default for user generated contents
if (!is_array($tags)) {
$tags = array('a', 'p', 'em', 'strong', 'ul', 'ol', 'li', 'code', 'pre', 'blockquote');
}
// Ensure the string is utf-8 encoded to protect against XSS exploits using
// different encodings.
$text = $field->value();
$encoding = str::encoding($text);
if (strtolower($encoding) !== 'utf-8') {
$text = str::convert($text, 'UTF-8//IGNORE', $encoding);
}
// Strip all raw html tags from the input, but allow them in code blocks
if (in_array('code', $tags)) {
$text = preg_replace_callback('/`[^`]+`|`{3}[^`]+`{3}|~{3}[^~]+~{3}/', function ($m) {
return str_replace(array('<', '>'), array('<', '>'), $m[0]);
}, $text);
}
$text = strip_tags($text);
// Setup markdown parser
$parsedown = new Parsedown();
$parsedown->setBreaksEnabled(true);
// Parse markdown and escape output. Now it is safe by default.
$html = $parsedown->text($text);
$html = htmlentities($html, ENT_COMPAT, 'utf-8');
// Convert links with specific protocols and a limited set of attributes