本文整理汇总了PHP中Spoon::getCharset方法的典型用法代码示例。如果您正苦于以下问题:PHP Spoon::getCharset方法的具体用法?PHP Spoon::getCharset怎么用?PHP Spoon::getCharset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spoon
的用法示例。
在下文中一共展示了Spoon::getCharset方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getValue
/**
* Retrieve the initial or submitted value.
*
* @return string
*/
public function getValue()
{
// redefine default value
$value = $this->value;
// form submitted
if ($this->isSubmitted()) {
// post/get data
$data = $this->getMethod(true);
// submitted by post (may be empty)
if (isset($data[$this->getName()])) {
$value = $data[$this->getName()];
$value = is_array($value) ? 'Array' : (string) $value;
// maximum length?
if (isset($this->attributes['maxlength']) && $this->attributes['maxlength'] > 0) {
$value = mb_substr($value, 0, (int) $this->attributes['maxlength'], Spoon::getCharset());
}
}
}
return $value;
}
示例2: getValue
/**
* Retrieve the initial or submitted value.
*
* @param bool[optional] $allowHTML Is HTML allowed?
* @return string
*/
public function getValue($allowHTML = null)
{
// redefine default value
$value = $this->value;
// added to form
if ($this->isSubmitted()) {
// post/get data
$data = $this->getMethod(true);
// submitted by post/get (may be empty)
if (isset($data[$this->attributes['name']])) {
// value
$value = $data[$this->getName()];
$value = is_scalar($value) ? (string) $value : 'Array';
if (!$allowHTML) {
$value = Spoon::getCharset() == 'utf-8' ? SpoonFilter::htmlspecialchars($value) : SpoonFilter::htmlentities($value);
}
}
}
return $value;
}
示例3: dump
/**
* Dumps the output of a variable in a more readable manner.
*
* @param mixed $var The variable to dump.
* @param bool[optional] $exit Should the code stop here?
*/
public static function dump($var, $exit = true)
{
ob_start();
var_dump($var);
$output = ob_get_clean();
// Make sure var_dump is not overridden by Xdebug before tweaking its output.
// Note that all truthy INI values ("On", "true", 1) are returned as "1" by ini_get().
$hasXdebugVarDump = extension_loaded('xdebug') && ini_get('xdebug.overload_var_dump') === '1';
if (!$hasXdebugVarDump) {
$output = preg_replace('/\\]\\=\\>\\n(\\s+)/m', '] => ', $output);
$output = '<pre>' . htmlspecialchars($output, ENT_QUOTES, Spoon::getCharset()) . '</pre>';
}
echo $output;
if ($exit) {
exit;
}
}
示例4: parseForms
/**
* Parse the forms.
*
* @return string The updated content, containing the parsed form tags.
* @param string $content The content that may contain the form tags.
*/
protected function parseForms($content)
{
// regex pattern
$pattern = '/\\{form:([a-z0-9_]+?)\\}?/siU';
// find matches
if (preg_match_all($pattern, $content, $matches)) {
// loop matches
foreach ($matches[1] as $name) {
// init vars
$search = array();
$replace = array();
// start & close tag
$search = array('{form:' . $name . '}', '{/form:' . $name . '}');
// using UTF-8 as charset
if (Spoon::getCharset() == 'utf-8') {
$replace[0] = '<?php
if(isset($this->forms[\'' . $name . '\']))
{
?><form accept-charset="UTF-8" action="<?php echo $this->forms[\'' . $name . '\']->getAction(); ?>" method="<?php echo $this->forms[\'' . $name . '\']->getMethod(); ?>"<?php echo $this->forms[\'' . $name . '\']->getParametersHTML(); ?>>
<?php echo $this->forms[\'' . $name . '\']->getField(\'form\')->parse();
if($this->forms[\'' . $name . '\']->getUseToken())
{
?><input type="hidden" name="form_token" id="<?php echo $this->forms[\'' . $name . '\']->getField(\'form_token\')->getAttribute(\'id\'); ?>" value="<?php echo htmlspecialchars($this->forms[\'' . $name . '\']->getField(\'form_token\')->getValue()); ?>" />
<?php } ?>';
} else {
$replace[0] = '<?php
if(isset($this->forms[\'' . $name . '\']))
{
?><form action="<?php echo $this->forms[\'' . $name . '\']->getAction(); ?>" method="<?php echo $this->forms[\'' . $name . '\']->getMethod(); ?>"<?php echo $this->forms[\'' . $name . '\']->getParametersHTML(); ?>>
<?php echo $this->forms[\'' . $name . '\']->getField(\'form\')->parse();
if($this->forms[\'' . $name . '\']->getUseToken())
{
?><input type="hidden" name="form_token" id="<?php echo $this->forms[\'' . $name . '\']->getField(\'form_token\')->getAttribute(\'id\'); ?>" value="<?php echo htmlentities($this->forms[\'' . $name . '\']->getField(\'form_token\')->getValue()); ?>" />
<?php } ?>';
}
$replace[1] = '</form>
<?php } ?>';
$content = str_replace($search, $replace, $content);
}
}
return $content;
}
示例5: uppercase
/**
* Transform the string to uppercase.
*
* @return string The string, completly uppercased.
* @param string $string The string that you want to apply this method on.
*/
public static function uppercase($string)
{
return mb_convert_case($string, MB_CASE_UPPER, Spoon::getCharset());
}
示例6: getValue
/**
* Retrieve the initial or submitted value.
*
* @return string
* @param bool[optional] $allowHTML Is HTML allowed?
*/
public function getValue($allowHTML = null)
{
// redefine html & default value
$allowHTML = $allowHTML !== null ? (bool) $allowHTML : $this->isHTML;
$value = $this->value;
// contains html
if ($this->isHTML) {
// set value
$value = Spoon::getCharset() == 'utf-8' ? SpoonFilter::htmlspecialchars($value) : SpoonFilter::htmlentities($value);
}
// form submitted
if ($this->isSubmitted()) {
// post/get data
$data = $this->getMethod(true);
// submitted by post (may be empty)
if (isset($data[$this->getName()])) {
// value
$value = isset($data[$this->getName()]) ? $data[$this->getName()] : '';
if (is_array($value)) {
$value = 'Array';
}
// maximum length?
if (isset($this->attributes['maxlength']) && $this->attributes['maxlength'] > 0) {
$value = mb_substr($value, 0, (int) $this->attributes['maxlength'], Spoon::getCharset());
}
// html allowed?
if (!$allowHTML) {
$value = Spoon::getCharset() == 'utf-8' ? SpoonFilter::htmlspecialchars($value) : SpoonFilter::htmlentities($value);
}
}
}
return $value;
}
示例7: setCharset
/**
* Changes the charset from standard utf-8 to your preferred value.
*
* @param string[optional] $charset The charset to use, default is utf-8.
*/
public function setCharset($charset = 'utf-8')
{
$this->charset = $charset !== null ? SpoonFilter::getValue($charset, Spoon::getCharsets(), Spoon::getCharset()) : Spoon::getCharset();
}
示例8: urlise
/**
* Prepares a string so that it can be used in urls.
*
* @return string The urlised string.
* @param string $value The value that should be urlised.
* @param string[optional] $charset The charset to use, default is based on Spoon::getCharset().
*/
public static function urlise($value, $charset = null)
{
// define charset
$charset = $charset !== null ? self::getValue($charset, Spoon::getCharsets(), Spoon::getCharset()) : Spoon::getCharset();
// reserved characters (RFC 3986)
$reservedCharacters = array('/', '?', ':', '@', '#', '[', ']', '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=');
// remove reserved characters
$value = str_replace($reservedCharacters, ' ', $value);
// replace double quote, since this one might cause problems in html (e.g. <a href="double"quote">)
$value = str_replace('"', ' ', $value);
// replace spaces by dashes
$value = str_replace(' ', '-', $value);
// only urlencode if not yet urlencoded
if (urldecode($value) == $value) {
// to lowercase
$value = mb_strtolower($value, $charset);
// urlencode
$value = urlencode($value);
}
// convert "--" to "-"
$value = preg_replace('/\\-+/', '-', $value);
// trim - signs
return trim($value, '-');
}
示例9: getMethod
/**
* Retrieve the method post/get.
*
* @return string
*/
public function getMethod()
{
// prevent against xss
$method = Spoon::getCharset() == 'utf-8' ? SpoonFilter::htmlspecialchars($this->method) : SpoonFilter::htmlentities($this->method);
return $method;
}
示例10: lowercase
/**
* Makes this string lowercase.
* syntax: {{ $string|lowercase }}.
*
*
* @param string $string The string that you want to apply this method on.
*
* @return string The string, completely lowercased.
*/
public static function lowercase($string)
{
return mb_convert_case($string, MB_CASE_LOWER, \Spoon::getCharset());
}