本文整理汇总了PHP中str::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP str::encode方法的具体用法?PHP str::encode怎么用?PHP str::encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类str
的用法示例。
在下文中一共展示了str::encode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: email
/**
* Generates an "a mailto" tag
*
* @param string $href The url for the a tag
* @param mixed $text The optional text. If null, the url will be used as text
* @param array $attr Additional attributes for the tag
* @return string the generated html
*/
public static function email($email, $text = null, $attr = array())
{
$email = str::encode($email, 3);
$attr = array_merge(array('href' => 'mailto:' . $email), $attr);
if (empty($text)) {
$text = $email;
}
return static::tag('a', $text, $attr);
}
示例2: captcha
/**
* Re-generates and returns the obfuscated captcha of the `calc` guard.
*
* @return string
*/
public function captcha()
{
$this->generateCaptcha();
return str::encode(s::get($this->id . '-captcha-label'));
}
示例3: uniform_captcha
/**
* Generates a new calculate captcha result for a Uniform form
*
* @param UniForm $form The form to generate the captcha for
* @return string A label like '4 plus 5'
*/
function uniform_captcha(UniForm $form)
{
list($a, $b) = array(rand(0, 9), rand(0, 9));
s::set($form->id() . '-captcha-result', $a + $b);
return str::encode($a . ' ' . l::get('uniform-calc-plus') . ' ' . $b);
}
示例4: email
/**
* Generates an "a mailto" tag
*
* @param string $email The url for the a tag
* @param mixed $text The optional text. If null, the url will be used as text
* @param array $attr Additional attributes for the tag
* @return string the generated html
*/
public static function email($email, $text = null, $attr = array())
{
if (empty($text)) {
// show only the eMail address without additional parameters (if the 'text' argument is empty)
$text = str::encode(a::first(str::split($email, '?')));
}
$email = str::encode($email);
$attr = array_merge(array('href' => 'mailto:' . $email), $attr);
return static::tag('a', $text, $attr);
}
示例5: function
<?php
/**
* Allows to obfuscate E-Mail addresses. At least we try to make it a bit more
* more difficult for bots to gather our mail addresses.
*
* @param Field $field The calling Kirby Field instance.
*/
field::$methods['obfuscate'] = function ($field) {
return str::encode($field->value());
};
/**
* Removes all HTML tags from the field value before parsing the field as
* markdown. Encodes all special characters of the resulting string as html
* entities to allow only a predefined list of tags. This method should be used
* to allow markdown in user generated contents.
*
* @see http://shiflett.org/blog/2007/mar/allowing-html-and-preventing-xss
*
* @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.