本文整理汇总了PHP中Strings::fixEncoding方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::fixEncoding方法的具体用法?PHP Strings::fixEncoding怎么用?PHP Strings::fixEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Strings
的用法示例。
在下文中一共展示了Strings::fixEncoding方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: jsonDump
/**
* Dump implementation for JSON.
* @param mixed variable to dump
* @param int current recursion level
* @return string
*/
private static function jsonDump(&$var, $level = 0)
{
if (is_bool($var) || is_null($var) || is_int($var) || is_float($var)) {
return $var;
} elseif (is_string($var)) {
if (Debugger::$maxLen && strlen($var) > Debugger::$maxLen) {
$var = substr($var, 0, Debugger::$maxLen) . " … ";
}
return Strings::fixEncoding($var);
} elseif (is_array($var)) {
static $marker;
if ($marker === NULL) {
$marker = uniqid("", TRUE);
}
if (isset($var[$marker])) {
return "…RECURSION…";
} elseif ($level < Debugger::$maxDepth || !Debugger::$maxDepth) {
$var[$marker] = TRUE;
$res = array();
foreach ($var as $k => &$v) {
if ($k !== $marker) {
$res[self::jsonDump($k)] = self::jsonDump($v, $level + 1);
}
}
unset($var[$marker]);
return $res;
} else {
return " … ";
}
} elseif (is_object($var)) {
$arr = (array) $var;
static $list = array();
if (in_array($var, $list, TRUE)) {
return "…RECURSION…";
} elseif ($level < Debugger::$maxDepth || !Debugger::$maxDepth) {
$list[] = $var;
$res = array("" => '(object) ' . get_class($var));
foreach ($arr as $k => &$v) {
if ($k[0] === "") {
$k = substr($k, strrpos($k, "") + 1);
}
$res[self::jsonDump($k)] = self::jsonDump($v, $level + 1);
}
array_pop($list);
return $res;
} else {
return " … ";
}
} elseif (is_resource($var)) {
return "resource " . get_resource_type($var);
} else {
return "unknown type";
}
}
示例2: createHttpRequest
/**
* Creates current HttpRequest object.
* @return HttpRequest
*/
public function createHttpRequest()
{
// DETECTS URI, base path and script path of the request.
$url = new UrlScript();
$url->scheme = !empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https' : 'http';
$url->user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
$url->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('');
}
$url->host = preg_match('#^[-._a-z0-9]+$#', $pair[0]) ? $pair[0] : '';
if (isset($pair[1])) {
$url->port = (int) $pair[1];
} elseif (isset($_SERVER['SERVER_PORT'])) {
$url->port = (int) $_SERVER['SERVER_PORT'];
}
// path & query
if (isset($_SERVER['REQUEST_URI'])) {
// Apache, IIS 6.0
$requestUrl = $_SERVER['REQUEST_URI'];
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) {
// IIS 5.0 (PHP as CGI ?)
$requestUrl = $_SERVER['ORIG_PATH_INFO'];
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') {
$requestUrl .= '?' . $_SERVER['QUERY_STRING'];
}
} else {
$requestUrl = '';
}
$requestUrl = Strings::replace($requestUrl, $this->urlFilters['url']);
$tmp = explode('?', $requestUrl, 2);
$url->path = Strings::replace($tmp[0], $this->urlFilters['path']);
$url->query = isset($tmp[1]) ? $tmp[1] : '';
// normalized url
$url->canonicalize();
$url->path = Strings::fixEncoding($url->path);
// detect script path
if (isset($_SERVER['SCRIPT_NAME'])) {
$script = $_SERVER['SCRIPT_NAME'];
} elseif (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'])), '\\', '/'), '/');
} else {
$script = '/';
}
$path = strtolower($url->path) . '/';
$script = strtolower($script) . '/';
$max = min(strlen($path), strlen($script));
for ($i = 0; $i < $max; $i++) {
if ($path[$i] !== $script[$i]) {
break;
} elseif ($path[$i] === '/') {
$url->scriptPath = substr($url->path, 0, $i + 1);
}
}
// GET, POST, COOKIE
$useFilter = !in_array(ini_get('filter.default'), array('', 'unsafe_raw')) || ini_get('filter.default_flags');
parse_str($url->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())) {
// 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 = Strings::fixEncoding($v);
} else {
if (!Strings::checkEncoding($v)) {
$v = iconv($this->encoding, 'UTF-8//IGNORE', $v);
}
$v = html_entity_decode($v, ENT_QUOTES, 'UTF-8');
//.........这里部分代码省略.........
示例3: 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 : MimeTypeDetector::fromString($content));
$part->setEncoding(preg_match('#(multipart|message)/#A', $contentType) ? self::ENCODING_8BIT : self::ENCODING_BASE64);
$part->setHeader('Content-Disposition', $disposition . '; filename="' . Strings::fixEncoding(basename($file)) . '"');
return $part;
}