本文整理汇总了PHP中Nette\String::fixEncoding方法的典型用法代码示例。如果您正苦于以下问题:PHP String::fixEncoding方法的具体用法?PHP String::fixEncoding怎么用?PHP String::fixEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\String
的用法示例。
在下文中一共展示了String::fixEncoding方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createHttpRequest
/**
* Creates current HttpRequest object.
* @return HttpRequest
*/
public function createHttpRequest()
{
// DETECTS URI, base path and script path of the request.
$uri = new UriScript;
$uri->scheme = isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https' : 'http';
$uri->user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
$uri->password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
// host & port
if (isset($_SERVER['HTTP_HOST'])) {
$pair = explode(':', $_SERVER['HTTP_HOST']);
} elseif (isset($_SERVER['SERVER_NAME'])) {
$pair = explode(':', $_SERVER['SERVER_NAME']);
} else {
$pair = array('');
}
$uri->host = preg_match('#^[-._a-z0-9]+$#', $pair[0]) ? $pair[0] : '';
if (isset($pair[1])) {
$uri->port = (int) $pair[1];
} elseif (isset($_SERVER['SERVER_PORT'])) {
$uri->port = (int) $_SERVER['SERVER_PORT'];
}
// path & query
if (isset($_SERVER['REQUEST_URI'])) { // Apache, IIS 6.0
$requestUri = $_SERVER['REQUEST_URI'];
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0 (PHP as CGI ?)
$requestUri = $_SERVER['ORIG_PATH_INFO'];
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') {
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
}
} else {
$requestUri = '';
}
$requestUri = String::replace($requestUri, $this->uriFilters['uri']);
$tmp = explode('?', $requestUri, 2);
$uri->path = String::replace($tmp[0], $this->uriFilters['path']);
$uri->query = isset($tmp[1]) ? $tmp[1] : '';
// normalized uri
$uri->canonicalize();
$uri->path = String::fixEncoding($uri->path);
// detect script path
if (isset($_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_FILENAME']) && strncmp($_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT'])) === 0) {
$script = '/' . ltrim(strtr(substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT'])), '\\', '/'), '/');
} elseif (isset($_SERVER['SCRIPT_NAME'])) {
$script = $_SERVER['SCRIPT_NAME'];
} else {
$script = '/';
}
if (strncasecmp($uri->path . '/', $script . '/', strlen($script) + 1) === 0) { // whole script in URL
$uri->scriptPath = substr($uri->path, 0, strlen($script));
} elseif (strncasecmp($uri->path, $script, strrpos($script, '/') + 1) === 0) { // directory part of script in URL
$uri->scriptPath = substr($uri->path, 0, strrpos($script, '/') + 1);
} else {
$uri->scriptPath = '/';
}
// GET, POST, COOKIE
$useFilter = (!in_array(ini_get('filter.default'), array('', 'unsafe_raw')) || ini_get('filter.default_flags'));
parse_str($uri->query, $query);
if (!$query) {
$query = $useFilter ? filter_input_array(INPUT_GET, FILTER_UNSAFE_RAW) : (empty($_GET) ? array() : $_GET);
}
$post = $useFilter ? filter_input_array(INPUT_POST, FILTER_UNSAFE_RAW) : (empty($_POST) ? array() : $_POST);
$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())) {
//.........这里部分代码省略.........
示例2: createAttachment
/**
* Creates file MIME part.
* @return MailMimePart
*/
private function createAttachment($file, $content, $contentType, $disposition)
{
$part = new MailMimePart;
if ($content === NULL) {
if (!is_file($file)) {
throw new \FileNotFoundException("File '$file' not found.");
}
if (!$contentType && $info = getimagesize($file)) {
$contentType = $info['mime'];
}
$part->setBody(file_get_contents($file));
} else {
$part->setBody((string) $content);
}
$part->setContentType($contentType ? $contentType : 'application/octet-stream');
$part->setEncoding(preg_match('#(multipart|message)/#A', $contentType) ? self::ENCODING_8BIT : self::ENCODING_BASE64);
$part->setHeader('Content-Disposition', $disposition . '; filename="' . String::fixEncoding(basename($file)) . '"');
return $part;
}
示例3: addAttachment
/**
* Adds attachment.
* @param string
* @param string
* @param string
* @return MailMimePart
*/
public function addAttachment($file, $content = NULL, $contentType = NULL)
{
$part = new MailMimePart();
$part->setBody($content === NULL ? $this->readFile($file, $contentType) : (string) $content);
$part->setContentType($contentType ? $contentType : 'application/octet-stream');
$part->setEncoding(self::ENCODING_BASE64);
$part->setHeader('Content-Disposition', 'attachment; filename="' . String::fixEncoding(basename($file)) . '"');
return $this->attachments[] = $part;
}
示例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);
}
示例5: createAttachment
/**
* Creates file MIME part.
* @return MailMimePart
*/
private function createAttachment($file, $content, $contentType, $disposition)
{
$part = new MailMimePart;
if ($content === NULL) {
$content = file_get_contents($file);
if ($content === FALSE) {
throw new \FileNotFoundException("Unable to read file '$file'.");
}
} else {
$content = (string) $content;
}
$part->setBody($content);
$part->setContentType($contentType ? $contentType : Nette\Tools::detectMimeTypeFromString($content));
$part->setEncoding(preg_match('#(multipart|message)/#A', $contentType) ? self::ENCODING_8BIT : self::ENCODING_BASE64);
$part->setHeader('Content-Disposition', $disposition . '; filename="' . String::fixEncoding(basename($file)) . '"');
return $part;
}