当前位置: 首页>>代码示例>>PHP>>正文


PHP String::checkEncoding方法代码示例

本文整理汇总了PHP中Nette\String::checkEncoding方法的典型用法代码示例。如果您正苦于以下问题:PHP String::checkEncoding方法的具体用法?PHP String::checkEncoding怎么用?PHP String::checkEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nette\String的用法示例。


在下文中一共展示了String::checkEncoding方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __invoke

 /**
  * Invokes filter.
  * @param  string
  * @return string
  */
 public function __invoke($s)
 {
     if (!String::checkEncoding($s)) {
         throw new LatteException('Template is not valid UTF-8 stream.');
     }
     if (!$this->macroRe) {
         $this->setDelimiters('\\{(?![\\s\'"{}*])', '\\}');
     }
     // context-aware escaping
     $this->context = LatteFilter::CONTEXT_NONE;
     $this->escape = '$template->escape';
     // initialize handlers
     $this->getHandler()->initialize($this, $s);
     // process all {tags} and <tags/>
     $s = $this->parse("\n" . $s);
     $this->getHandler()->finalize($s);
     return $s;
 }
开发者ID:Balvan,项目名称:nette,代码行数:23,代码来源:LatteFilter.php

示例2: setHeader

 /**
  * Sets a header.
  * @param  string
  * @param  string|array  value or pair email => name
  * @param  bool
  * @return MailMimePart  provides a fluent interface
  */
 public function setHeader($name, $value, $append = FALSE)
 {
     if (!$name || preg_match('#[^a-z0-9-]#i', $name)) {
         throw new \InvalidArgumentException("Header name must be non-empty alphanumeric string, '{$name}' given.");
     }
     if ($value == NULL) {
         // intentionally ==
         if (!$append) {
             unset($this->headers[$name]);
         }
     } elseif (is_array($value)) {
         // email
         $tmp =& $this->headers[$name];
         if (!$append || !is_array($tmp)) {
             $tmp = array();
         }
         foreach ($value as $email => $name) {
             if ($name !== NULL && !Nette\String::checkEncoding($name)) {
                 throw new \InvalidArgumentException("Name is not valid UTF-8 string.");
             }
             if (!preg_match('#^[^@",\\s]+@[^@",\\s]+\\.[a-z]{2,10}$#i', $email)) {
                 throw new \InvalidArgumentException("Email address '{$email}' is not valid.");
             }
             if (preg_match('#[\\r\\n]#', $name)) {
                 throw new \InvalidArgumentException("Name cannot contain the line separator.");
             }
             $tmp[$email] = $name;
         }
     } else {
         $value = (string) $value;
         if (!Nette\String::checkEncoding($value)) {
             throw new \InvalidArgumentException("Header is not valid UTF-8 string.");
         }
         $this->headers[$name] = preg_replace('#[\\r\\n]+#', ' ', $value);
     }
     return $this;
 }
开发者ID:nella,项目名称:ActiveMapper,代码行数:44,代码来源:MailMimePart.php

示例3: createHttpRequest


//.........这里部分代码省略.........
		$cookies = $useFilter ? filter_input_array(INPUT_COOKIE, FILTER_UNSAFE_RAW) : (empty($_COOKIE) ? array() : $_COOKIE);

		$gpc = (bool) get_magic_quotes_gpc();
		$old = error_reporting(error_reporting() ^ E_NOTICE);

		// remove fucking quotes and check (and optionally convert) encoding
		if ($gpc || $this->encoding) {
			$utf = strcasecmp($this->encoding, 'UTF-8') === 0;
			$list = array(& $query, & $post, & $cookies);
			while (list($key, $val) = each($list)) {
				foreach ($val as $k => $v) {
					unset($list[$key][$k]);

					if ($gpc) {
						$k = stripslashes($k);
					}

					if ($this->encoding && is_string($k) && (preg_match(self::NONCHARS, $k) || preg_last_error())) {
						// invalid key -> ignore

					} elseif (is_array($v)) {
						$list[$key][$k] = $v;
						$list[] = & $list[$key][$k];

					} else {
						if ($gpc && !$useFilter) {
							$v = stripSlashes($v);
						}
						if ($this->encoding) {
							if ($utf) {
								$v = String::fixEncoding($v);

							} else {
								if (!String::checkEncoding($v)) {
									$v = iconv($this->encoding, 'UTF-8//IGNORE', $v);
								}
								$v = html_entity_decode($v, ENT_QUOTES, 'UTF-8');
							}
							$v = preg_replace(self::NONCHARS, '', $v);
						}
						$list[$key][$k] = $v;
					}
				}
			}
			unset($list, $key, $val, $k, $v);
		}


		// FILES and create HttpUploadedFile objects
		$files = array();
		$list = array();
		if (!empty($_FILES)) {
			foreach ($_FILES as $k => $v) {
				if ($this->encoding && is_string($k) && (preg_match(self::NONCHARS, $k) || preg_last_error())) continue;
				$v['@'] = & $files[$k];
				$list[] = $v;
			}
		}

		while (list(, $v) = each($list)) {
			if (!isset($v['name'])) {
				continue;

			} elseif (!is_array($v['name'])) {
				if ($gpc) {
					$v['name'] = stripSlashes($v['name']);
开发者ID:newPOPE,项目名称:screencast,代码行数:67,代码来源:HttpRequestFactory.php

示例4: initialize

 /**
  * Initializes $this->query, $this->files, $this->cookies and $this->files arrays
  * @return void
  */
 public function initialize()
 {
     $filter = !in_array(ini_get("filter.default"), array("", "unsafe_raw")) || ini_get("filter.default_flags");
     parse_str($this->getUri()->query, $this->query);
     if (!$this->query) {
         $this->query = $filter ? filter_input_array(INPUT_GET, FILTER_UNSAFE_RAW) : (empty($_GET) ? array() : $_GET);
     }
     $this->post = $filter ? filter_input_array(INPUT_POST, FILTER_UNSAFE_RAW) : (empty($_POST) ? array() : $_POST);
     $this->cookies = $filter ? filter_input_array(INPUT_COOKIE, FILTER_UNSAFE_RAW) : (empty($_COOKIE) ? array() : $_COOKIE);
     $gpc = (bool) get_magic_quotes_gpc();
     $enc = (bool) $this->encoding;
     $old = error_reporting(error_reporting() ^ E_NOTICE);
     $nonChars = '#[^\\x09\\x0A\\x0D\\x20-\\x7E\\xA0-\\x{10FFFF}]#u';
     // remove fucking quotes and check (and optionally convert) encoding
     if ($gpc || $enc) {
         $utf = strcasecmp($this->encoding, 'UTF-8') === 0;
         $list = array(&$this->query, &$this->post, &$this->cookies);
         while (list($key, $val) = each($list)) {
             foreach ($val as $k => $v) {
                 unset($list[$key][$k]);
                 if ($gpc) {
                     $k = stripslashes($k);
                 }
                 if ($enc && is_string($k) && (preg_match($nonChars, $k) || preg_last_error())) {
                     // invalid key -> ignore
                 } elseif (is_array($v)) {
                     $list[$key][$k] = $v;
                     $list[] =& $list[$key][$k];
                 } else {
                     if ($gpc && !$filter) {
                         $v = stripSlashes($v);
                     }
                     if ($enc) {
                         if ($utf) {
                             $v = String::fixEncoding($v);
                         } else {
                             if (!String::checkEncoding($v)) {
                                 $v = iconv($this->encoding, 'UTF-8//IGNORE', $v);
                             }
                             $v = html_entity_decode($v, ENT_QUOTES, 'UTF-8');
                         }
                         $v = preg_replace($nonChars, '', $v);
                     }
                     $list[$key][$k] = $v;
                 }
             }
         }
         unset($list, $key, $val, $k, $v);
     }
     // structure $files and create HttpUploadedFile objects
     $this->files = array();
     $list = array();
     if (!empty($_FILES)) {
         foreach ($_FILES as $k => $v) {
             if ($enc && is_string($k) && (preg_match($nonChars, $k) || preg_last_error())) {
                 continue;
             }
             $v['@'] =& $this->files[$k];
             $list[] = $v;
         }
     }
     while (list(, $v) = each($list)) {
         if (!isset($v['name'])) {
             continue;
         } elseif (!is_array($v['name'])) {
             if ($gpc) {
                 $v['name'] = stripSlashes($v['name']);
             }
             if ($enc) {
                 $v['name'] = preg_replace($nonChars, '', String::fixEncoding($v['name']));
             }
             $v['@'] = new HttpUploadedFile($v);
             continue;
         }
         foreach ($v['name'] as $k => $foo) {
             if ($enc && is_string($k) && (preg_match($nonChars, $k) || preg_last_error())) {
                 continue;
             }
             $list[] = array('name' => $v['name'][$k], 'type' => $v['type'][$k], 'size' => $v['size'][$k], 'tmp_name' => $v['tmp_name'][$k], 'error' => $v['error'][$k], '@' => &$v['@'][$k]);
         }
     }
     error_reporting($old);
 }
开发者ID:nella,项目名称:ActiveMapper,代码行数:87,代码来源:HttpRequest.php


注:本文中的Nette\String::checkEncoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。